Forum Discussion
How to apply policy initiative Azure
Hello Mightly Wizards,
trying to Assign an Azure Policy Initiative via power shell:
step 1:
New-AzPolicySetDefinition -Name 'DATABASE_OPEN_SOURCE_ID' -ManagementGroupName MGname -DisplayName 'DATABASES OPEN SOURCE' -PolicyDefinition "C:\path\initiatives\DATABASES_-_OPEN_SOURCE\policyset1.json"
note policyset1.json comes from exporting to GitHub Initiative definition and assignment
error
ew-AzPolicySetDefinition : InvalidRequestContent : The request content was invalid and could not be deserialized: 'Could not find member 'properties' on object of type
'PolicyDefinitionReference'. Path 'properties.policyDefinitions[0].properties', line 7, position 21.'.
CorrelationId: f01ee272-73c1-43b7-99fc-51a67650463a
At line:1 char:1
+ New-AzPolicySetDefinition -Name 'DATABASE_OPEN_SOURCE_ID' -Management ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzPolicySetDefinition], ErrorResponseMessageException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzurePolicySetDefinitionCmdlet
First question. How does this file have to be formatted? can you give me an example?
Second question how to assign this definition? With New-AzPolicyAssignment?
Thank you in advance for yout reply.
giuseppe
1 Reply
To properly define and assign an Azure Policy Initiative (Policy Set) using PowerShell, the JSON file must conform to the official initiative schema, and assignments are performed with the New-AzPolicyAssignment cmdlet. The error you encountered indicates that the JSON structure is invalid, policy definition references should not include a nested properties block. Instead, each reference must directly specify the policyDefinitionId and any required parameters.
https://learn.microsoft.com/en-us/azure/governance/policy/concepts/initiative-definition-structure
https://learn.microsoft.com/en-us/azure/governance/policy/assign-policy-powershell