Skip to content

Instantly share code, notes, and snippets.

@ehrnst
Created June 11, 2020 13:10
Show Gist options
  • Save ehrnst/00eb71b9493d80d2c75931872a294b8a to your computer and use it in GitHub Desktop.
Save ehrnst/00eb71b9493d80d2c75931872a294b8a to your computer and use it in GitHub Desktop.
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