Search code examples
azureazure-application-insightsazure-powershellazure-monitor

Powershell command to fetch Azure monitor alert rules is not working


I have created an alert rule and associated it with a VM. Now trying to fetch the alert rule through Powershell, but getting null. What's wrong with this code ?

Get-AzAlertRule -ResourceGroupName 'pacbldnew'

see the alert rule powershell code returning null


Solution

  • That is just a warning. The command should work, make sure the alert rule is existing.

    enter image description here

    Update1:

    Try the command below to get what you want.

    enter image description here

    Get-AzResource -ResourceGroupName joywebapp -ResourceType microsoft.insights/metricAlerts 
    

    enter image description here

    Update2:

    If you want to get the details, try the script as below.

    $names = (Get-AzResource -ResourceGroupName joywebapp -ResourceType microsoft.insights/metricAlerts).Name
    foreach($name in $names){
        Get-AzResource -ResourceGroupName joywebapp -Name $name -ResourceType microsoft.insights/metricAlerts | ConvertTo-Json
    }
    

    enter image description here