I am attempting to add an alert action for all alert types in a resource group using powershell.
I am able to get the properties of the alerts using :
$resource = Get-AzResource -ResourceType microsoft.insights/metricAlerts -ResourceGroupName "MyResourceGroup" -ExpandProperties
write-output($resource.Properties.actions | Format-List *)
This returns the following :
actionGroupId : /subscriptions/345345/resourceGroups/MyResourceGroup/providers/m
icrosoft.insights/actionGroups/Teams-Alerts
webHookProperties : @{teamsChannel=MyChannel}
I would like to update both of these values, or add them if they do not exist. So starting with the actionGroupId, I tried :
$resource = Get-AzResource -ResourceType microsoft.insights/metricAlerts -ResourceGroupName "MyResourceGroup"
$Resource.Properties.actions.actionGroupId = "/subscriptions/456546/resourceGroups/MyResourceGroup/providers/microsoft.insights/actionGroups/Teams-Alerts"
$Resource | Set-AzResource -Force
But that returns with an error :
The property 'actionGroupId' cannot be found on this object. Verify that the property exists and can be set.
SO how do I update or add an actiongroup to an alert?
Thanks!