Horje
Microsoft Azure - Creating Custom Policy Initiative using PowerShell

In this article we’ll see how we can create an Azure Custom Policy Initiative Definition with a JSON file using the Azure PowerShell commands in simple easy steps.

What is Custom Policy Initiative Definition?

Custom Policy Initiative is a collection or group of policy definitions that are grouped to apply policies together for a specific organization or project goal. The advantage of using these initiatives simplifies the management of organization policies by grouping a set of policies together as one.

Implementation:

Step 1: Login to Azure Portal

Step 2: Access the Cloud Shell or Windows PowerShell 

Step 3: Create a JSON file to add Custom Policy Initiatives with <add_filename>.json

Here, in the JSON file, we have added two custom build in policies definition Id’s

[
   {
    "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/8dfab9c4-fe7b-49ad-85e4-1e9be085358f",
   },
   {
    "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/a1840de2-8088-4ea8-b153-b4c723e9cb01",
   }
]

Step 4: Run the below commands to create a custom azure policy initiative

Create policy initiative definition using Azure PowerShell Command

New-AzPolicySetDefinition `
-Name '<add_initiative_definition_name>' `
-DisplayName '<add_initiative_definition_display_name>' `
-Policy '<add_policy_location_path>'

or you can assign the command to a variable

$initiative_policy = New-AzPolicySetDefinition -Name '<add_initiative_definition_name>'
-DisplayName '<add_initiative_definition_display_name>' -Policy '<add_initiative_policy_path>'

Example:

New-AzPolicySetDefinition `
-Name 'Azure Custom Policy Initiative Definition 01' `
-DisplayName 'Azure Custom Policy Initiative Definition' `
-Policy 'custom-initiative-01.json'

Step 5: To verify the status in Azure Policy Initiatives, Go to policy from Azure Portal and check your assigned Custom Policy Initiative Definition Display Name. In this case, it is ‘Azure Custom Policy Initiative Definition’ as I have mentioned in the above example.




Reffered: https://www.geeksforgeeks.org


DevOps

Related
Microsoft Azure - Cognitive Service Text Analytics in Web App Containers Microsoft Azure - Cognitive Service Text Analytics in Web App Containers
Microsoft Azure - Messaging with Azure Web PubSub Microsoft Azure - Messaging with Azure Web PubSub
Microsoft Azure - Using Power Apps in VS Code Microsoft Azure - Using Power Apps in VS Code
Microsoft Azure - Developing ARM Templates using Azure Bicep Microsoft Azure - Developing ARM Templates using Azure Bicep
Microsoft Azure - Using Azure Form Recognizer Microsoft Azure - Using Azure Form Recognizer

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12