Azure / Azure/azure-powershell
New-AzPolicyDefinition : A parameter cannot be found that matches parameter name 'Depth'.
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 3d 14h
- Merged PRs (30d)
- 54
Description
### 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
+ $policyDefinition = New-AzPolicyDefinition -Name 'SharedKeyAccess ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-AzPolicyDefinition], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,New-AzPolicyDefinition
### Issue script & Debug output
```PowerShell
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
```PowerShell
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
```PowerShell
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_
Contributor guide
Research direction
Start with the New-AzPolicyDefinition invocation in SharedKeyAccessDisabledPolicy.ps1 at line 43 and compare its available parameters with the installed Az module versions. Reproduce the command using the reported PowerShell and module environment, then verify that the policy-definition script runs without the NamedParameterNotFound error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, powershell
- Domain
- cli, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100