PS /Users/myname> echo $name
Deploy - Configure Log Analytics extension to be enabled on Windows virtual machines
PS /Users/myname> az policy definition show --name $name
(InvalidPolicyDefinitionName) The policy definition name 'Deploy - Configure Log Analytics extension to be enabled on Windows virtual machines' is invalid. The policy definition name length must not exceed '64' characters.
Code: InvalidPolicyDefinitionName
Message: The policy definition name 'Deploy - Configure Log Analytics extension to be enabled on Windows virtual machines' is invalid. The policy definition name length must not exceed '64' characters.
The maximum length for a policy definition is not 64, but 128, infact the policy actually exists in Azure so it was defined and accepted by Azure. Why is pwsh complaining?
CodePudding user response:
I tried to reproduce the same in my environment and got the same error as below:
The error usually occurs if creating New Policy definition along with definition Name
parameter value exceeds 64 characters.
I tried to create a Policy by using below command:
New-AzPolicyDefinition -Name 'VMPolicyDefinition' -DisplayName 'Deploy - Configure Log Analytics extension to be enabled on Windows virtual machines' -Policy '{"if":{"field":"type","equals":"Microsoft.Compute/virtualMachines"},"then":{"effect":"deny"}}'
In the Portal, Policy got created successfully like below:
Policy Definition Resource Name will be like below:
Note that: The policy definition Display Name
has length limit of 128 characters and policy Definition Resource Name
has the limit of 64 characters.
Reference: