Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-AzPolicyDefinition : A parameter cannot be found that matches parameter name 'Depth'. #24971

Open
peterboba opened this issue May 22, 2024 · 6 comments
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported needs-triage This is a new issue that needs to be triaged to the appropriate team.

Comments

@peterboba
Copy link

Description

Get-AzPolicyDefinition fails with "A parameter cannot be found that matches parameter name 'Depth'."

Works fine with older version of Az.Resources

Import-Module Az.Resources -RequiredVersion 6.16.2
Get-AzPolicyDefinition -ResourceId "/providers/Microsoft.Authorization/policyDefinitions/96670d01-0a4d-4649-9c89-2d3abc0a5025"
WARNING: Upcoming breaking changes in the cmdlet 'Get-AzPolicyDefinition' :
- The output type 'Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.Policy.PsPolicyDefinition' is
changing
- The following properties in the output type are being deprecated : 'Properties'
- The following properties are being added to the output type : 'Description' 'DisplayName' 'Metadata' 'Mode'
'Parameters' 'PolicyRule' 'PolicyType'
- The change is expected to take effect in Az version : '12.0.0'
- The change is expected to take effect in Az.Resources version : '7.1.0'
Note : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other
information on breaking changes in Azure PowerShell.


Name               : 96670d01-0a4d-4649-9c89-2d3abc0a5025
ResourceId         : /providers/Microsoft.Authorization/policyDefinitions/96670d01-0a4d-4649-9c89-2d3abc0a5025
ResourceName       : 96670d01-0a4d-4649-9c89-2d3abc0a5025
ResourceType       : Microsoft.Authorization/policyDefinitions
SubscriptionId     :
Properties         : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.Policy.PsPolicyDefinitionPropertie
                     s
PolicyDefinitionId : /providers/Microsoft.Authorization/policyDefinitions/96670d01-0a4d-4649-9c89-2d3abc0a5025

WARNING: You're using Az.Resources version 6.16.2. The latest version of Az.Resources is 7.1.0. Upgrade your Az modules
 using the following commands:
  Update-Module Az.* -WhatIf    -- Simulate updating your Az modules.
  Update-Module Az.*            -- Update your Az modules.

Issue script & Debug output

> Get-AzPolicyDefinition -ResourceId "/providers/Microsoft.Authorization/policyDefinitions/96670d01-0a4d-4649-9c89-2d3abc0a5025"
DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing:
DEBUG: CmdletProcessRecordStart:
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated:
/providers/Microsoft.Authorization/policyDefinitions/96670d01-0a4d-4649-9c89-2d3abc0a5025?api-version=2023-04-01
DEBUG: RequestCreated:
/providers/Microsoft.Authorization/policyDefinitions/96670d01-0a4d-4649-9c89-2d3abc0a5025?api-version=2023-04-01
DEBUG: HeaderParametersAdded:
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/providers/Microsoft.Authorization/policyDefinitions/96670d01-0a4d-4649-9c89-2d3abc0a5025?a
pi-version=2023-04-01

Headers:
x-ms-unique-id                : 6
x-ms-client-request-id        : 9031a9bd-5332-42af-b357-54d8ea9feee0
CommandName                   : &
FullCommandName               : Get-AzPolicyDefinitionBuilt_GetViaIdentity
ParameterSetName              : __AllParameterSets
User-Agent                    : AzurePowershell/v0.0.0,PSVersion/v5.1.19041.4412,Az.Policy/7.1.0

Body:


DEBUG: BeforeCall:
DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma                        : no-cache
Strict-Transport-Security     : max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-tenant-reads: 11999
x-ms-request-id               : 086712ea-fae8-41de-9837-34ac6f929963
x-ms-correlation-request-id   : 086712ea-fae8-41de-9837-34ac6f929963
x-ms-routing-request-id       : WESTEUROPE:20240522T090110Z:086712ea-fae8-41de-9837-34ac6f929963
X-Content-Type-Options        : nosniff
X-Cache                       : CONFIG_NOCACHE
X-MSEdge-Ref                  : Ref A: 5113119AA4C64549AECBFBEFF6B88FEF Ref B: AMS231020615047 Ref C:
2024-05-22T09:01:10Z
Cache-Control                 : no-cache
Date                          : Wed, 22 May 2024 09:01:10 GMT

Body:
{
  "properties": {
    "displayName": "Require a tag on resource groups",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "Enforces existence of a tag on resource groups.",
    "metadata": {
      "version": "1.0.0",
      "category": "Tags"
    },
    "version": "1.0.0",
    "parameters": {
      "tagName": {
        "type": "String",
        "metadata": {
          "displayName": "Tag Name",
          "description": "Name of the tag, such as 'environment'"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Resources/subscriptions/resourceGroups"
          },
          {
            "field": "[concat('tags[', parameters('tagName'), ']')]",
            "exists": "false"
          }
        ]
      },
      "then": {
        "effect": "deny"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/96670d01-0a4d-4649-9c89-2d3abc0a5025",
  "type": "Microsoft.Authorization/policyDefinitions",
  "name": "96670d01-0a4d-4649-9c89-2d3abc0a5025"
}

DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
DEBUG: Finally:
DEBUG: CmdletAfterAPICall:
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd:
DEBUG: CmdletProcessRecordEnd:
Get-AzPolicyDefinition : A parameter cannot be found that matches parameter name 'Depth'.
At line:1 char:1
+ Get-AzPolicyDefinition -ResourceId "/providers/Microsoft.Authorizatio ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-AzPolicyDefinition], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Get-AzPolicyDefinition

> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     3.0.0      Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear...
Script     7.1.0      Az.Resources                        {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDeny...
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con...
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, En...
Script     2.0.0      PSReadline                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PS...

Environment data

Name                           Value
----                           -----
PSVersion                      5.1.19041.4412
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.4412
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Module versions

Get-Module Az*

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     3.0.0      Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear...
Script     7.1.0      Az.Resources                        {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDeny...

Error output

No response

@peterboba peterboba added bug This issue requires a change to an existing behavior in the product in order to be resolved. needs-triage This is a new issue that needs to be triaged to the appropriate team. labels May 22, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added customer-reported needs-triage This is a new issue that needs to be triaged to the appropriate team. and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels May 22, 2024
@peterboba
Copy link
Author

I see no issues on latest Linux Powershell

PS /> Get-AzPolicyDefinition -ResourceId "/providers/Microsoft.Authorization/policyDefinitions/96670d01-0a4d-4649-9c89-2d3abc0a5025"

Metadata                     : @{version=1.0.0; category=Tags}
Parameter                    : @{tagName=}
PolicyRule                   : @{if=; then=}
Description                  : Enforces existence of a tag on resource groups.
DisplayName                  : Require a tag on resource groups
Id                           : /providers/Microsoft.Authorization/policyDefinitions/96670d01-0a4d-4649-9c89-2d3abc0a5025
Mode                         : All
Name                         : 96670d01-0a4d-4649-9c89-2d3abc0a5025
PolicyType                   : BuiltIn
SystemDataCreatedAt          : 
SystemDataCreatedBy          : 
SystemDataCreatedByType      : 
SystemDataLastModifiedAt     : 
SystemDataLastModifiedBy     : 
SystemDataLastModifiedByType : 
Type                         : Microsoft.Authorization/policyDefinitions
Version                      : 1.0.0
Versions                     : {1.0.0}

PS /> Get-Module                                                                                                                    

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     3.0.0                 Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script     7.1.0                 Az.Resources                        {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment…}
Manifest   7.0.0.0               Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty…}
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object…}
Script     2.3.5                 PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHand…

PS /> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Debian GNU/Linux 12 (bookworm)
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

@VeryEarly
Copy link
Contributor

VeryEarly commented May 23, 2024

Hi @peterboba ,

There is a piece of script in the new version of Az.Resources was not supported by windows powershell (5.x), please try using powershell core (7.x) as a workaround for now. Meanwhile we will improve the compatibility of the script.

Thanks

@VeryEarly VeryEarly self-assigned this May 23, 2024
@persiaAziz
Copy link

Facing the same issue with New-AzPolicyDefinition

@ShruthiChetan
Copy link

I am facing the same issue with New-AzPolicySetDefinition

Get-AzPolicySetDefinition : A parameter cannot be found that matches parameter name 'Depth'.
At line:1 char:1

  • $PolicySetDefinition = Get-AzPolicySetDefinition | Where-Object Resou ...
  •   + CategoryInfo          : InvalidArgument: (:) [Get-AzPolicySetDefinition], ParameterBindingException      
      + FullyQualifiedErrorId : NamedParameterNotFound,Get-AzPolicySetDefinition
    
    

When can we have a fix for this?

@cmptscpeacock
Copy link

Same.

7.1.0 Az.Resources

Get-AzPolicyAssignment
Get-AzPolicyAssignment : A parameter cannot be found that matches parameter name 'Depth'.
At line:1 char:1

  • Get-AzPolicyAssignment
  •   + CategoryInfo          : InvalidArgument: (:) [Get-AzPolicyAssignment], ParameterBindingException
      + FullyQualifiedErrorId : NamedParameterNotFound,Get-AzPolicyAssignment
    

mentat9 added a commit to mentat9/azure-powershell that referenced this issue Jun 15, 2024
Fix for GH issue: Azure#24971
Fix for "Get-AzPolicyExemption requests unnecessary parameter for Get-AzPolicyExemption in v12"
Complete support for getting and assigning versioned policy definitions and sets
VeryEarly pushed a commit to VeryEarly/azure-powershell that referenced this issue Jun 15, 2024
Fix for GH issue: Azure#24971
Fix for "Get-AzPolicyExemption requests unnecessary parameter for Get-AzPolicyExemption in v12"
Complete support for getting and assigning versioned policy definitions and sets
mentat9 added a commit to mentat9/azure-powershell that referenced this issue Jun 15, 2024
…ns and sets

Fix for GH issue: Azure#25084
Fix for GH issue: Azure#24971
Fix for "Get-AzPolicyExemption requests unnecessary parameter for Get-AzPolicyExemption in v12"
VeryEarly pushed a commit that referenced this issue Jun 17, 2024
* Handful of cleanup items (no recording files)
 - Fix default formatting for output objects
 - Remove leftover auto-generated InputObject parameters
 - Remove Helpers.psm1, which was replaced by Helpers.ps1
 - Add info to error message in test harness

* Implement -Version and -ListVersion parameters on Get-AzPolicy[Set]Definition
Add tests for -Version and -ListVersion

* Add recordings for all non-backcompat tests

* Add rest of recording files (backcompat)

* Tag tests that create big recording files with LiveOnly to get under the Github PR maximum size

* Rerecord all tests

* Add back InputObject parameters to Remove-* cmdlets.

* Complete support for getting and assigning versioned policy definitions and sets
Fix for GH issue: #25084
Fix for GH issue: #24971
Fix for "Get-AzPolicyExemption requests unnecessary parameter for Get-AzPolicyExemption in v12"

* Re-record tests
@VeryEarly
Copy link
Contributor

Hi all,

Fix for this issue has been merged, please try new release on 2024-07-02 PST

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported needs-triage This is a new issue that needs to be triaged to the appropriate team.
Projects
None yet
Development

No branches or pull requests

5 participants