Jul 22 2020 07:07 PM - edited Jul 22 2020 07:07 PM
$Policy=
'{
"properties": {
"displayName": "Disable-IP-Forwarding",
"policyType": "Custom",
"mode": "All",
"description": "Disable-IP-Forwarding-Test.",
"metadata": {
"version": "1.0.2",
"category": "Security Center"
},
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "AuditIfNotExists"
}
},
"policyRule": {
"if": {
"field": "type",
"in": [
"Microsoft.Compute/virtualMachines",
"Microsoft.ClassicCompute/virtualMachines"
]
},
"then": {
"effect": "[parameters(effect)]",
"details": {
"type": "Microsoft.Security/complianceResults",
"name": "disableIPForwarding",
"existenceCondition": {
"field": "Microsoft.Security/complianceResults/resourceStatus",
"in": [
"Monitored",
"OffByPolicy",
"Healthy"
]
}
}
}
}
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/Disable-IP-Forwarding",
"type": "Microsoft.Authorization/policyDefinitions",
"name": "Disable-IP-Forwarding"
}'
$definition = New-AzPolicyDefinition -Name "Disable-IP-Forwarding" -Description "Disable-IP-Forwarding-Test." -Policy $Policy
Hello,
I am working on "New-AzPolicyDefinition" in Powershell however I am getting stuck in JSON format.
I am taking JSON from the Built-in Policy from the Azure portal but the same JSON when placing in PowerShell ISE editor, it is throwing below error in PowerShell.
New-AzPolicyDefinition : InvalidPolicyRule : Failed to parse policy rule: 'Could not find member 'properties' on object of type 'PolicyRuleDefinition'. Path 'properties'.'.
CorrelationId: 7e754d56-2e8e-4323-8650-ae620bb60573
At line:70 char:15
+ ... efinition = New-AzPolicyDefinition -Name "Disable-IP-Forwarding" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzPolicyDefinition], ErrorResponseMessageException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzurePolicyDefinitionCmdlet