Azure Resource Graph (ARG) Query to List All Failed Policy Deployments
![](https://techprofile.blob.core.windows.net/images/e3b24b33a24b479ab16c1883dc177240.png)
When using Azure Policy, in particular a policy with Deploy If Not Exist (DINE), naturally the policy will try to remediate anything that doesn't align to the policy definition.
However, if there is something that prevents the Policy Deployment from executing properly, the Resource Group's Deployments will show a Status of Failed
.
This is different than an error when actually remediating, or something being non-compliant.
I want to create an Azure Resource Graph (ARG) query that will list all of the Resource Groups that have any "Failed" deployments, where Deployment Name contains PolicyDeployment_
.
I've used something like the following, but this doesn't seem to find the actual failed policy deployments. I tried cross-referencing for similar ways to use Azure Activity Logs as well.
resourcecontainers
| where type == "microsoft.resources/subscriptions/resourcegroups"
| project subscriptionId, resourceGroup=name, location, tostring(properties['provisioningState'])
Any ideas would be appreciated.