I am trying to create az azure policy definition using powershell and I am receiving the following error.
New-AzPolicyDefinition_CreateExpanded : Failed to parse policy rule: 'Error converting value "@{effect=audit}" to type
'Microsoft.WindowsAzure.Governance.PolicyService.Policy.Expression.Schema.EffectExpressionDefinition'. Path 'then'.'.
At C:\Program Files\WindowsPowerShell\Modules\Az.Resources\7.2.0\Policy.Autorest\custom\New-AzPolicyDefinition.ps1:256 char:19
+ $scriptCmd = {& $wrappedCmd @calledParameters}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ({ }:<>f__AnonymousType1) [New-AzPolicyDefinition_CreateExpanded], Exception
+ FullyQualifiedErrorId : InvalidPolicyRule,Microsoft.Azure.PowerShell.Cmdlets.Policy.Cmdlets.NewAzPolicyDefinition_CreateExpanded
I tried sample: AuditStorageAccounts.json
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Storage/storageAccounts"
},
{
"field": "Microsoft.Storage/storageAccounts/networkAcls.defaultAction",
"equals": "Allow"
}
]
},
"then": {
"effect": "audit"
}
}
Powershell Script:
New-AzPolicyDefinition -Name 'TestAuditStorageAccounts' `
-DisplayName 'Test - Audit Storage Accounts Open to Public Networks' `
-Policy 'AuditStorageAccounts.json'
I would like to create an azure policy definition programatically to assign tag to azure resources.
I am trying to create az azure policy definition using powershell and I am receiving the following error.
New-AzPolicyDefinition_CreateExpanded : Failed to parse policy rule: 'Error converting value "@{effect=audit}" to type
'Microsoft.WindowsAzure.Governance.PolicyService.Policy.Expression.Schema.EffectExpressionDefinition'. Path 'then'.'.
At C:\Program Files\WindowsPowerShell\Modules\Az.Resources\7.2.0\Policy.Autorest\custom\New-AzPolicyDefinition.ps1:256 char:19
+ $scriptCmd = {& $wrappedCmd @calledParameters}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ({ }:<>f__AnonymousType1) [New-AzPolicyDefinition_CreateExpanded], Exception
+ FullyQualifiedErrorId : InvalidPolicyRule,Microsoft.Azure.PowerShell.Cmdlets.Policy.Cmdlets.NewAzPolicyDefinition_CreateExpanded
I tried sample: AuditStorageAccounts.json
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Storage/storageAccounts"
},
{
"field": "Microsoft.Storage/storageAccounts/networkAcls.defaultAction",
"equals": "Allow"
}
]
},
"then": {
"effect": "audit"
}
}
Powershell Script:
New-AzPolicyDefinition -Name 'TestAuditStorageAccounts' `
-DisplayName 'Test - Audit Storage Accounts Open to Public Networks' `
-Policy 'AuditStorageAccounts.json'
I would like to create an azure policy definition programatically to assign tag to azure resources.
Just check here. so many samples Azure provided. Many of them are about tag policy definitions. Simply modify them and pass in the parameters.
{
. – Santiago Squarzon Commented Jan 2 at 4:20