How do you check if an alert rule exists by its ResourceId, and then remove it. What is the syntax for the check?
Get-AzScheduledQueryRule -ResourceId "/subscriptions.....Id"
Remove-AzScheduledQueryRule -ResourceId "/subscriptions/.....Id"
CodePudding user response:
As mentioned in above comments, You can use below PowerShell Script which will validate whether any ScheduledQueryRule is present for that particular ResourceId or not.
if exists it will delete the ScheduledQueryRule for that ResourceId.
Here is the PowerShell Script:
Connect-AzAccount
$rulelist = Get-AzScheduledQueryRule
foreach($item in $rulelist){
if($item.id -contains "<requiredresourceid>"){
Remove-AzScheduledQueryRule -ResourceId $item.Id
}
}
