Initiative Definition policy remediation in Powershell

Mateusz Przezdziecki 21 Reputation points
2022-07-06T18:39:58.887+00:00

How can you automate creating remediation tasks for non compliant policies within an initiative definition in PowerShell?

All the documentation for remediation in PowerShell uses the policy assignment id, but with initiative definitions, there is only one assignment id which is for the group which does not work.

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,120 questions
Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
797 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,382 questions
0 comments No comments
{count} votes

Accepted answer
  1. SwathiDhanwada-MSFT 17,556 Reputation points
    2022-07-07T05:35:23.407+00:00

    @Mateusz Przezdziecki Welcome to Microsoft Q & A Community Forum. I understand that you are trying to create remediation tasks for the policies within Initiative. Here is sample example on how to create a remediation task at resource group scope for a policy set definition assignment.

    $policyAssignmentId = "/subscriptions/f0710c27-9663-4c05-19f8-1b4be01e86a5/resourceGroups/myRG/providers/Microsoft.Authorization/policyAssignments/2deae24764b447c29af7c309"  
    Start-AzPolicyRemediation -ResourceGroupName "myRG" -PolicyAssignmentId $policyAssignmentId -PolicyDefinitionReferenceId "0349234412441" -Name "remediation1"  
    

    To retrieve policy definitions id within the initiative, you can use below command.

    (Get-AzPolicySetDefinition -ResourceId /providers/Microsoft.Authorization/policySetDefinitions/55f3eceb-5573-4f18-9695-226972c6d74a).Properties.PolicyDefinitions  
    

    For more information, refer Start-AzPolicyRemediation and Get-AzPolicySetDefinition documents.

    0 comments No comments

0 additional answers

Sort by: Most helpful