You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cmdlets may ignore parameter aliases in case of naming collisions with other parameters; e.g., "Get-ChildItem -d" #4739
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifWG-Enginecore PowerShell engine, interpreter, and runtime
A parameter alias is designed to give an unambiguous alternative name - typically shorter than the original name - to a parameter.
For instance, Get-ChildItem's -Directory parameter (switch) has two aliases: -ad and -d.
Thus, both Get-ChildItem -ad and Get-ChildItem -d should work the same as Get-ChildItem -Directory.
However, Get-ChildItem -d is currently misinterpreted as the -Depth parameter.
The same problem may affect other cmdlets analogously.
Steps to reproduce
Get-ChildItem-ad
Get-ChildItem-d
Expected behavior
Both commands should list the subdirectories of the current directory.
Actual behavior
Get-ChildItem -ad succeeds, but Get-ChildItem -d fails with the following error:
Get-ChildItem : Missing an argument for parameter 'Depth'. Specify a parameter of type 'System.UInt32' and try again.
Environment data
PowerShell Core v6.0.0-beta.6 on macOS 10.12.6
PowerShell Core v6.0.0-beta.6 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.0-beta.6 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.502 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
-Directory is not a parameter of Get-ChildItem cmdlet, while -Depth is. -Directory is dynamic parameter of FileSystem provider. Thus when PowerShell bind static parameters of Get-ChildItem cmdlet -d is unambiguously resolved to -Depth. PowerShell does not try to find better match for already bound static parameters.
functionf {
[CmdletBinding()]
param($A1)
dynamicparam {
Write-Host"A1 paramter have value '$A1'"$DynParams= [System.Management.Automation.RuntimeDefinedParameterDictionary]::new()
$A2Param= [System.Management.Automation.RuntimeDefinedParameter]::new('A2', [object], ([Parameter]::new(), [Alias]::new('A','B')))
$DynParams.Add('A2',$A2Param)
$DynParams
}
end {
"A1 parameter: '$A1'""A2 parameter: '$($A2Param.Value)'"
}
}
f -A 42
f -B 42
Reacted by Rain Sallow (/u/ta11ow) and Michael Klement
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifWG-Enginecore PowerShell engine, interpreter, and runtime
Activity
PetSerAl commentedon Apr 7, 2019
-Directoryis not a parameter ofGet-ChildItemcmdlet, while-Depthis.-Directoryis dynamic parameter ofFileSystemprovider. Thus when PowerShell bind static parameters ofGet-ChildItemcmdlet-dis unambiguously resolved to-Depth. PowerShell does not try to find better match for already bound static parameters.mklement0 commentedon Apr 7, 2019
As usual, thanks for digging deeper, PetSerAl.
Given the current behavior, the actionable conclusions are:
Remove the
dalias from theDirectoryparameter declaration, because it is effectively inaccessible.Update the documentation accordingly.
Leaving it at that is an option, but the bigger question is:
Can dynamic parameters be considered alongside the static ones when looking for ambiguity / unambiguous aliases?
From a UX perspective, this seems preferable.
Or are there good (a) conceptual or (b) technical reasons not to do that?
mklement0 commentedon Feb 3, 2021
Closed in favor of #14700.