Created
June 11, 2020 13:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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