I am trying to disable an Azure alert rule via Powershell, which will eventually go into a runbook, scheduled every week.
Connect-AzAccount
Set-AzContext -Subscription "<subscription-id>"
# Specify the resource group and name of the alert rule to disable
$resourceGroupName = "MyResourceGroup"
$ruleName = "MyAlertRuleName"
# Update the alert rule
Update-AzScheduledQueryRule -ResourceGroupName $resourceGroupName -Name $ruleName -Enabled
According to Microsoft documentation, -Enabled
works as a switch parameter. Which I would imagine would switch from enabled to disabled, and vice versa depending on the alert rule's current state
This works going from Disabled > Enabled. It does not however work going from Enabled > Disabled, it just stays at its Enabled state
I then try using a different module script
# Update the alert rule
Update-AzActivityLogAlert -ResourceGroupName $resourceGroupName -Name $ruleName -Enabled 0
But I get the error
Resource 'MyAlertRuleName' was disallowed by policy. Reasons: 'Sorry your object cannot live here'. See error details for policy resource IDs.
Am I doing something wrong? The account I'm using to connect to Azure is my own, which can disable/enable alert rules freely