Each of the SDK can export policy definitions. To get it into JSON from PowerShell for example, you could export them with Get-AzPolicyDefinition and then something like:
$object[0].Properties | ConvertTo-Json
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I am trying to find a script to export all existing policy definitions that are configured in our environment. I am hoping to export them into a json format that I can then place into source control for CI/CD.
Does anybody know if this exists? Or if not could anyone point me in the right direction for how to achieve this?
Thanks
Each of the SDK can export policy definitions. To get it into JSON from PowerShell for example, you could export them with Get-AzPolicyDefinition and then something like:
$object[0].Properties | ConvertTo-Json
You can export as below using azure CLI
Policy export definition
$policies = az policy definition list | Out-File 'c:\xxxx\policy_definition.json'
from the above file you can also pick type of policies you want
$policies = 'c:\xxxx\policy_definition.json" | ConvertFrom-Json
$final = ($policies | Where-Object {$_.policyType -eq 'Custom'}) | ConvertTo-Json
$final | Out-File ''c:\xxxx\custompolicy_definations.json'