[英]Remove Azure alert rule if exists using Remove-AzScheduledQueryRule
How do you check if an alert rule exists by its ResourceId, and then remove it.如何通过其 ResourceId 检查是否存在警报规则,然后将其删除。 What is the syntax for the check?检查的语法是什么?
Get-AzScheduledQueryRule -ResourceId "/subscriptions.....Id"
Remove-AzScheduledQueryRule -ResourceId "/subscriptions/.....Id"
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.正如上面评论中提到的,您可以使用下面的 PowerShell 脚本,该脚本将验证该特定 ResourceId 是否存在任何ScheduledQueryRule
。
if exists it will delete the ScheduledQueryRule
for that ResourceId.如果存在,它将删除该 ResourceId 的ScheduledQueryRule
。
Here is the PowerShell Script:这是 PowerShell 脚本:
Connect-AzAccount
$rulelist = Get-AzScheduledQueryRule
foreach($item in $rulelist){
if($item.id -contains "<requiredresourceid>"){
Remove-AzScheduledQueryRule -ResourceId $item.Id
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.