Skip to content

New-AzPolicyDefinition: Length cannot be less than zero. (Parameter 'length') #15377

@egullbrandsson

Description

@egullbrandsson

Getting the above error when running the deploy from PowerShell 7.2.0 preview 5.
PowerShell 7.1.3 works as expected.

  1. Installed PowerShell 7.2.0 preview 5
  2. Logged into Azure
  3. Selected my subscription.
  4. Tried to deploy the new Azure Policy Definition.
New-AzPolicyDefinition -Name "allowed-locations3" `
    -DisplayName "Allowed locations3" `
    -Policy 'https://raw.githubusercontent.com/Azure/azure-policy/master/samples/built-in-policy/allowed-locations/azurepolicy.rules.json' `
    -Parameter 'https://raw.githubusercontent.com/Azure/azure-policy/master/samples/built-in-policy/allowed-locations/azurepolicy.parameters.json' `
    -Mode Indexed

Expected behavior


 ~\Desktop >  New-AzPolicyDefinition -Name "allowed-locations3" `
    -DisplayName "Allowed locations3" `
    -Policy 'https://raw.githubusercontent.com/Azure/azure-policy/master/samples/built-in-policy/allowed-locations/azurepolicy.rules.json' `
    -Parameter 'https://raw.githubusercontent.com/Azure/azure-policy/master/samples/built-in-policy/allowed-locations/azurepolicy.parameters.json' `
    -Mode Indexed

Name               : allowed-locations3
ResourceId         : /subscriptions/XXXXXX-XXXX-XXXX-XXXX-XXXXXX/providers/Microsoft.Authorization/policyDefinitions/allowed-locations3
ResourceName       : allowed-locations3
ResourceType       : Microsoft.Authorization/policyDefinitions
SubscriptionId     : XXXXXX-XXXX-XXXX-XXXX-XXXXXX
Properties         : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.Policy.PsPolicyDefinitionProperties
PolicyDefinitionId : /subscriptions/XXXXXX-XXXX-XXXX-XXXX-XXXXXX/providers/Microsoft.Authorization/policyDefinitions/allowed-locations3

Actual behavior


C:\Program Files\PowerShell\7-preview> New-AzPolicyDefinition -Name "allowed-locations3" `
>>     -DisplayName "Allowed locations3" `
>>     -Policy 'https://raw.githubusercontent.com/Azure/azure-policy/master/samples/built-in-policy/allowed-locations/azurepolicy.rules.json' `
>>     -Parameter 'https://raw.githubusercontent.com/Azure/azure-policy/master/samples/built-in-policy/allowed-locations/azurepolicy.parameters.json' `
>>     -Mode Indexed
New-AzPolicyDefinition: Length cannot be less than zero. (Parameter 'length')

C:\Program Files\PowerShell\7-preview>  Get-Error

Exception             :
    Type       : System.ArgumentOutOfRangeException
    Message    : Length cannot be less than zero. (Parameter 'length')
    ParamName  : length
    TargetSite :
        Name          : HandleException
        DeclaringType : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase
        MemberType    : Method
        Module        : Microsoft.Azure.PowerShell.Cmdlets.ResourceManager.dll
    StackTrace :
   at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.HandleException(ExceptionDispatchInfo capturedException)
   at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.ExecuteCmdlet()
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.<ExecuteSynchronouslyOrAsJob>b__3_0(T c)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
    Source     : Microsoft.Azure.PowerShell.Cmdlets.ResourceManager
    HResult    : -2146233086
CategoryInfo          : CloseError: (:) [New-AzPolicyDefinition], ArgumentOutOfRangeException
FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzurePolicyDefinitionCmdlet
InvocationInfo        :
    MyCommand        : New-AzPolicyDefinition
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 5
    Line             : New-AzPolicyDefinition -Name "allowed-locations3" `

    PositionMessage  : At line:1 char:1
                       + New-AzPolicyDefinition -Name "allowed-locations3" `
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : New-AzPolicyDefinition
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data


Name                           Value
----                           -----
PSVersion                      7.2.0-preview.5
PSEdition                      Core
GitCommitId                    7.2.0-preview.5
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-DuplicateThe issue is a duplicate.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions