Share via

How to list SQL Database Alert Rules using Powershell

John Couch 181 Reputation points
2021-12-21T19:23:51.02+00:00

I am trying to generate a report output that shows

Az SQL Database / Alert Rule

I have tried several things, but nothing really outputs. For example, I have tried:

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

But it does not return ALL rules defined. I have 3 rules, and Data IO % is the one NOT returned. The two rules for Max Worker Threads do return. And the above command does not return the name of the database associated to the Alert Rule.

Azure Monitor
Azure Monitor

An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.

Azure SQL Database
0 comments No comments

Answer accepted by question author

Alberto Morillo 35,506 Reputation points MVP Volunteer Moderator
2021-12-21T20:59:14.89+00:00

What happen if you run the following:

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

What about using Azure CLI as explained here and as shown below:

az monitor alert list  

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.