我正在嘗試通過 powershell 禁用警報規則,但出現以下錯誤:
Get-AzMetricAlertRuleV2 -ResourceGroupName "myresourcegroupname" -Name "alertname" | Add-AzMetricAlertRuleV2 -DisableRule
Add-AzMetricAlertRuleV2:無法驗證引數“TargetResourceRegion”上的引數。引數為 null 或空。提供一個不為 null 或空的引數,然后重試該命令。
我試過沒有 | 添加-AzMetricAlertRuleV2 -DisableRule:
Get-AzMetricAlertRuleV2 -ResourceGroupName "myresourcegroupname" -Name "alertname"
Output:
Criteria : {Metric1}
Actions : {/subscriptions/subscriptionguid/resourceGroups/myresourcegroupname/providers/microsoft.insights/actionGroups/actiongroupname}
ResourceGroup : myresourcegroupname
Description :
Severity : 3
Enabled : True
Scopes : {/subscriptions/subscriptionguid/resourceGroups/myresourcegroupname/providers/Microsoft.Sql/servers/myservername/elasticpools/myelasticpoolname}
EvaluationFrequency : 00:01:00
WindowSize : 00:01:00
TargetResourceType : Microsoft.Sql/servers/elasticpools
TargetResourceRegion :
AutoMitigate : True
LastUpdatedTime :
IsMigrated :
Id : /subscriptions/3subscriptionguid/resourceGroups/myresourcegroupname/providers/microsoft.insights/metricAlerts/alertname
Name : alertname
Type : Microsoft.Insights/metricAlerts
Location : global
Tags : {}
Kind :
Etag :
我之前的命令告訴我“TargetResourceRegion”為空或為空。這正好對應于上面的輸出。但是,如何使用空的 TargetResourceRegion 從 powershell 禁用該警報規則?
uj5u.com熱心網友回復:
我們在本地環境中對此進行了測驗,以下陳述基于我們的分析。
根據
- 通過添加
|Add-AzMetricAlertRuleV2禁用特定指標警報規則來運行相同的 cmdlet 。

更新答案:
我們還在本地環境中針對 sql 彈性池測驗了此 cmdlet,使用以下 cmdlet 我們可以禁用警報。
Get-AzMetricAlertRuleV2 -ResourceGroupName '<resourcegrp>' -Name '<AlertName>'|Add-AzMetricAlertRuleV2 -DisableRule -TargetResourceRegion " "
這是供參考的示例螢屏截圖:

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/420893.html
標籤:
上一篇:PowerShell:在用戶之間靜態地在桌面快捷方式中使用$env:userprofile
下一篇:列印出核心數
