Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create Azure policy set remediation task with powershell https://adatum.no/?p=6903
# in case you have multiple subscriptions...
select-azsubscription -SubscriptionName "SubscriptionName"
# get all non-compliant policies that can be remediated
$nonCompliantPolicies = Get-AzPolicyState | Where-Object { $_.ComplianceState -eq "NonCompliant" -and $_.PolicyDefinitionAction -eq "deployIfNotExists" }
# loop through ans start individual tasks per policy
foreach ($policy in $nonCompliantPolicies) {
$remediationName = "rem." + $policy.PolicyDefinitionName
Start-AzPolicyRemediation -Name $remediationName -PolicyAssignmentId $policy.PolicyAssignmentId -PolicyDefinitionReferenceId $policy.PolicyDefinitionReferenceId
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.