问题
Is it possible to list metric alerts in Azure with PowerShell? I could only find:
Get-AzureRmAlertRule
But that only gives me the "classic" alerts and not the metric alerts I have in the portal.
I can get all the metric alerts through the API by using the metricalerts/listbyresourcegroup end-point.
Anyone that has any idea on if it is possible to get them through a PowerShell script?
回答1:
You could try using the generic Get-AzureRmResource cmdlet with a resource type filter, e.g.
# Retrieve alert rule
$rule = Get-AzureRmResource -ResourceType Microsoft.Insights/alertRules -ResourceGroupName "myResourceGroup" -Name "my-rule";
# Retrieve alerts for this rule
Get-AzureRmAlertHistory -ResourceId $rule.ResourceId -StartTime (Get-Date).AddHours(-1) -EndTime (Get-Date)
来源:https://stackoverflow.com/questions/54533976/how-to-list-metric-alerts-in-azure-with-powershell