0

I have got azure policy auto remediation in place, however the process is a manual one where the remediation tasks needs to be manually triggered. I was wondering if there is a way to programmatically trigger the running of the remediation job.

I can see the remediation tasks, however they are a manual step that has to be triggered when required. I would ideally love to automate the process.

Any thoughts on a potential solution here.

1
  • 1
    If you enable remediation while assigning the policy, the remediation will trigger automatically without manual intervention. If still want to start remediation, you can use PowerShell Cmd: Start-AzPolicyRemediation -PolicyAssignmentId $policyAssignmentId -Name "remediation1" Commented Sep 10, 2024 at 5:50

1 Answer 1

1

Programmatically triggering azure policy remediation

Here is the Azure PowerShell code to trigger the remediation without manual intervention., You want to automate this process, you can use Azure automation account, follow the stack link to create automation account.

$policyassignmentNames = @("Storage enable Policy", "Network Security Group rule deny", "NSG_Rule_Deny", "JIT Port deny", "Azure Policy to modify Log analytics workspace destination of a data collection rule","JIM_Port_3389 and 22 Restricted")

$policyAssignments = Get-AzPolicyAssignment -BackwardCompatible -WarningAction silentlyContinue | Where-Object { $policyassignmentNames -contains $_.DisplayName }

foreach ($policy in $policyAssignments){

$remediatename= "Remeadite." + $policy.DisplayName

write-output "Starting the remediation with Policy Assignment Name :$($policy.DisplayName)"

Start-AzPolicyRemediation -Name "$remediatename" -PolicyAssignmentId $policy.PolicyAssignmentId -ResourceDiscoveryMode ReEvaluateCompliance
}

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Please do not upload images of code/data/errors. Aside from that: the question is off-topic, as it's just a requirement and asking someone to build a solution - that's not the purpose of Stack Overflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.