Open In App

How to Export Definitions in an Azure Initiative Policy to CSV File?

Last Updated : 18 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

An Azure Policy Initiative Definition is a collection of Azure Policy definitions that are grouped together. Here in this article, we will show how to export Azure policy definitions that are listed in an Azure policy initiative. We will be using the Azure Resource Graph KQL query to export the Azure Policy definitions that are grouped together in an Azure Policy initiative. This is the base KQL query that will be used it export Definitions in an Azure Initiative Policy.

policyresources
| where type =~ 'Microsoft.Authorization/PolicySetDefinitions'
| where name == "add custom policy definition id"

Steps to Export Definitions in an Initiative Policy

Step 1: Open Azure Portal

Step 2: Access Azure Resource Graph Explorer from Azure global search

RGQ-04

Step 3: Select the desired scope of your selection

RGQ-03

Step 4: Add the following KQL Azure Resource Graph Explorer

policyresources
| where type =~ 'Microsoft.Authorization/PolicySetDefinitions'
| where name == "add custom policy definition name or id"
| extend policysetDefId = tolower(id)
| extend policyDefinitions = properties.policyDefinitions
| mv-expand policyDefinition = policyDefinitions limit 400
| extend policyDefinitionId = tolower(policyDefinition.policyDefinitionId)
| extend policyDefinitionReferenceId = policyDefinition.policyDefinitionReferenceId
| extend groupNames = policyDefinition.groupNames
| parse policyDefinitionId with "/providers/microsoft.authorization/policydefinitions/" policyId
| project policyDefinitionReferenceId, groupNames, policyId, policyDefinitionId

This query will list all Azure Policy definitions that are part of an Azure Policy initiative. We are filtering the following details to export the list.

  • Policy Definition Reference Id
  • Policy Group Name
  • Policy Id
  • Policy Definition Id

Export-Query

To list Policy Definition Reference Parameters use the following query:

policyresources
| where type =~ 'Microsoft.Authorization/PolicySetDefinitions'
| where name == "add custom policy definition name or id"
| extend policysetDefId = tolower(id)
| extend policyDefinitions = properties.policyDefinitions
| mv-expand policyDefinition = policyDefinitions limit 400
| extend policyDefinitionId = tolower(policyDefinition.policyDefinitionId)
| extend policyDefinitionReferenceId = policyDefinition.policyDefinitionReferenceId
| extend policyDefinitionReferenceParameters = policyDefinition.parameters
| extend groupNames = policyDefinition.groupNames
| parse policyDefinitionId with "/providers/microsoft.authorization/policydefinitions/" policyId
| project policyDefinitionReferenceId, policyDefinitionReferenceParameters, groupNames, policyId, policyDefinitionId

With this query you can get the details of

  • Policy Definition Reference Id
  • Policy Definition Reference Parameters
  • Policy Group Name
  • Policy Id
  • Policy Definition Id

To download the results click on Download as CSV.

Sample Output:

Export

That’s it! These are the simple steps to to Export Definitions in an Azure Initiative Policy to CSV File. You can follow the same steps to export other policy definitions. I have linked the reference for Azure Policy Initiative for Knowledge base. I hope this helps! Happy Learning.

Frequently Asked Questions

1. Is there a direct option to export Definitions in an Azure Initiative Policy to CSV File in Azure Portal?

As of now, Azure Portal does not have an export feature to save the definitions list to a csv file.

2. Is it possible to export Azure Initiative Policy definitions from Azure PowerShell?

Yes, it is possible to export Azure Initiative Policy definitions from Azure PowerShell, but you need to do some script in PowerShell to export the list. However KQL query is the best is simplest and best option for you.

3. What is format of Azure Initiative Policy definitions in Azure Portal?

The format of Azure Initiative Policy definitions in the Azure portal is JSON. It contains JSON object properties like name and description of Policy Initiative and array of Azure Policy definitions.

Also, Read


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads