0

我正在通过 powershell 部署拒绝策略并收到以下错误

New-AzPolicyDefinition : InvalidPolicyRule : Failed to parse policy rule: 'Could not find member 'properties' on object of type 'PolicyRuleDefinition'. Path 'properties'.'.

我使用的代码是: 1 New-AzPolicyDefinition -name 'externalDeny' -Policy 'C:\tmp\denyoms-temp.json' -Parameter 'C:\tmp\denyoms-param.json' `

策略模板如下。

模板文件 - https://pastebin.com/embed_js/HrjUWrvf 参数 - https://pastebin.com/embed_js/QxEX92jf

我想可能是标签,在此先感谢。

4

1 回答 1

3

问题出在模板上。根据此文档,模板应采用以下格式(template.json):

{
        "if": {
            "allOf": [
                {
                    "field": "tags",
                    "Equals": "ExternalVM"
                },
                {
                    "field": "type",
                    "equals": "Microsoft.Compute/virtualMachines/extensions"
                },
                {
                    "field": "Microsoft.Compute/virtualMachines/extensions/publisher",
                    "equals": "Microsoft.Compute"
                },
                {
                    "field": "Microsoft.Compute/virtualMachines/extensions/type",
                    "in": "[parameters(\'notAllowedExtensions\')]"
                }
            ]
        },
        "then": {
            "effect": "deny"
        }
}

此外,根据您应用的条件,您的参数文件中的模板需要一个“数组”类型:

{
    "notAllowedExtensions": {
        "type": "Array",
        "metadata": {
            "description": "The list of extensions that will be denied. Example: BGInfo, CustomScriptExtension, JsonAADDomainExtension, VMAccessAgent.",
            "displayName": "OmsAgentForLinux"
        }
    }
}

使用此命令执行:

New-AzPolicyDefinition -Name 'Not allowed VM Extensions' -Description 'This policy governs which VM extensions that are explicitly denied.' -Policy 'template.json'  -Parameter 'parameters.json'

希望这可以帮助!

于 2020-04-06T11:12:55.897 回答