‘
subscriptionId = 'abc'
$nonCompliantPolicies = Get-AzPolicyState -SubscriptionId $subscriptionId
# Define a custom object for each non-compliant resource
$customObjects = $nonCompliantPolicies | ForEach-Object {
[PSCustomObject]@{
PolicyName = $_.PolicyDefinitionName
ComplianceState = $_.ComplianceState
ResourceType = $_.ResourceType
ResourceGroup = $_.ResourceGroup
SubscriptionId = $_. subscriptionId
IsCompliant = $_.IsCompliant
PolicyAssignmentScope =$_.PolicyAssignmentScope
}
}
# Export the custom objects to a CSV file
$customObjects | Format-Table -AutoSize
‘
Policy name is generating GUID value but i need descriptive name kinldy provide a solution as how i can modify my code to get descriptive name of the policies rather than guid id
2
Answers
Policy definition name
may be different frompolicy assignment name
sometimes, so need also include both to show more infomations.The
Get-AzPolicyState
command will display the policy definition name as a GUID instead of the descriptive nameTo get the names using the policy definition GUID, you can use the script below to retrieve the policy definition names from the GUID.
Output
Excel Output