Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.22k stars 3.83k forks source link

New-AzPolicyDefinition : A parameter cannot be found that matches parameter name 'Depth'. #25418

Open YingChen1996 opened 3 months ago

YingChen1996 commented 3 months ago

Description

(base) PS C:\Users\cy> powershell -ExecutionPolicy Bypass -File .ps1 -SubscriptionIds ''

New-AzPolicyDefinition : A parameter cannot be found that matches parameter name 'Depth'. At D:\repro\microsoft\promptflow\examples\tutorials\flow-deploy\azure-app-service\SharedKeyAccessDisabledPolicy.ps1:43 char:5

Issue script & Debug output

param (
    [string[]]$SubscriptionIds
)

Connect-AzAccount

foreach ($SubId in $SubscriptionIds) {
    Set-AzContext -SubscriptionId $SubId

    $policy = '{
        "if": {
            "allOf": [{
                    "field": "type",
                    "equals": "Microsoft.Storage/storageAccounts"
                },
                {
                    "not": {
                        "field": "Microsoft.Storage/storageAccounts/allowSharedKeyAccess",
                        "equals": "false"
                    }
                }
            ]
        },
        "then": {
            "effect": "modify",
            "details": {
                "roleDefinitionIds": [
                    "/providers/Microsoft.Authorization/roleDefinitions/17d1049b-9a84-46fb-8f53-869881c3d3ab"
                ],
                "conflictEffect": "deny",
                "operations": [{
                            "operation": "addOrReplace",
                            "field": "Microsoft.Storage/storageAccounts/allowSharedKeyAccess",
                            "value": false
                    }
                ]
            }
        }
    }'

    $parameters = '{}'

    $policyDefinition = New-AzPolicyDefinition -Name 'SharedKeyAccessDisabled' -Description 'Ensure Storage with shared key access disabled.' -Policy $policy -Parameter $parameters -Mode All

    $policyAssignment = New-AzPolicyAssignment -Name "SharedKeyAccessDisabled" -Scope "/subscriptions/$SubId" -PolicyDefinition $policyDefinition

    Write-Host "Policy assigned to subscription: $SubId"
}

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.3
PSEdition                      Core
GitCommitId                    7.4.3
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     11.2.0                Az                                  Core,Desk
Script     8.3.0                 Az                                  Core,Desk
Script     2.15.0                Az.Accounts                         Core,Desk {Disable-AzDataCollection, Disable-AzContextAutosave, Enable-AzDataCollection…
Script     2.10.1                Az.Accounts                         Core,Desk {Disable-AzDataCollection, Disable-AzContextAutosave, Enable-AzDataCollection…
Script     2.0.0                 Az.Advisor                          Core,Desk {Disable-AzAdvisorRecommendation, Enable-AzAdvisorRecommendation, Get-AzAdvis…
Script     1.1.2                 Az.Advisor                          Core,Desk {Get-AzAdvisorRecommendation, Enable-AzAdvisorRecommendation, Disable-AzAdvis…
Script     6.0.0                 Az.Aks                              Core,Desk {Get-AzAksCluster, New-AzAksCluster, Remove-AzAksCluster, Import-AzAksCredent…
Script     4.3.0                 Az.Aks                              Core,Desk {Get-AzAksCluster, New-AzAksCluster, Remove-AzAksCluster, Import-AzAksCredent…
Script     1.1.4                 Az.AnalysisServices                 Core,Desk {Resume-AzAnalysisServicesServer, Suspend-AzAnalysisServicesServer, Get-AzAna…
Script     4.0.2                 Az.ApiManagement                    Core,Desk {Add-AzApiManagementApiToGateway, Add-AzApiManagementApiToProduct, Add-AzApiM…
Script     3.0.1                 Az.ApiManagement                    Core,Desk {Add-AzApiManagementApiToGateway, Add-AzApiManagementApiToProduct, Add-AzApiM…
Script     1.0.0                 Az.App                              Core,Desk {Disable-AzContainerAppRevision, Enable-AzContainerAppRevision, Get-AzContain…

Error output

No response

isra-fel commented 3 months ago

Adding @mentat9

microsoft-github-policy-service[bot] commented 3 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @aperezcloud, @kenieva.

mentat9 commented 2 months ago

Adding @mentat9

This is fixed in the recent 7.2.0 Az.Resources release.