在一个答案中在 superuser.com 上,指出gci -af
是 的别名gci -File
。该信息是正确的,并且两个命令行都产生相同的文件列表结果。
但是,我找不到-af
定义该别名的文档来源。例如,它没有在主Get-ChildItem 的文档页面。
当命令名称本身缩写时,命令行参数是否有另一组别名,如使用gci
for Get-ChildItem
?
答案1
参数列表如下文档,您可以发现它-af
确实被记录为 的别名-File
。
-文件
要获取文件列表,请使用 File 参数。您可以将 Recurse 参数与 File 一起使用。
类型:SwitchParameter
别名: af
职位: 命名
默认值:无
接受管道输入:False
接受通配符:False
答案2
答案3
所有 cmdlet 和参数别名都可以这样查看:
# Get named aliases: Get-Alias | Out-GridView -PassThru -Title 'Available aliases' # Get cmdlet / function parameter aliases: (Get-Command Get-ChildItem).Parameters.Values | where aliases | select Name, Aliases | Out-GridView -PassThru -Title 'Alias results for a given cmdlet or function.'
上述方法的另一种方式,但与您所述的更改略有不同,但结果相同:
Function Get-CommandAlias { [CmdletBinding()] [Alias('gca')] Param ( [string]$CommandName ) Get-Command $CommandName | Select-Object -expand ParameterSets | Foreach-Object { $PSItem.Parameters} | Where-Object { $PSItem.Aliases -ne $null } | Select-Object Name, Aliases -Unique | Sort-Object Name } gca -CommandName Get-Help # Results: Name Aliases ---- ------- Debug {db} ErrorAction {ea} ErrorVariable {ev} InformationAction {infa} InformationVariable {iv} OutBuffer {ob} OutVariable {ov} PipelineVariable {pv} Verbose {vb} WarningAction {wa} WarningVariable {wv}
在深入研究 parm 别名之前,还有一点:
# Get a list of all commandlets for the specified name: Get-Command -Name '*Help*' -CommandType Cmdlet | Out-GridView -PassThru -Title 'Available named cmdlet' Get-Command -CommandType Cmdlet | Where-Object { $PSItem.parameters.keys -match 'credential'} | Out-GridView -PassThru -Title 'Available cmdlets which has a specific parameter' # Get a list of all functions: Get-Command -CommandType Function | Out-GridView -PassThru -Title 'Available functions' # Get a list of all functions for the specified name: Get-Command -Name '*Help*' -CommandType Function | Out-GridView -PassThru -Title 'Available named functions' # Find all cmdlets / functions with a target parameter: Get-Command -CommandType Function | Where-Object { $PSItem.parameters.keys -match 'credential'} | Out-GridView -PassThru -Title 'Available functions which has a specific parameter' # Get specifics for a module, cmdlet, or function: (Get-Command -Name Get-Help).Parameters (Get-Command -Name Get-Help).Parameters.Keys Get-help -Name Get-Help -Examples Get-help -Name Get-Help -Full Get-help -Name Get-Help -Online # Get parameter that accepts pipeline input: Get-Help Get-ADUser -Parameter '*' | Where-Object {$PSItem.pipelineInput -match 'true'} | Select-Object -Property '*' # Get property enums/options for a specifc cmdlet/function: # 1: (Get-Service | Select-Object -First 1).Status.GetType() [System.ServiceProcess.ServiceControllerStatus]::GetNames([System.ServiceProcess.ServiceControllerStatus]) # 2: (Get-Service)[0].Status.GetType().GetEnumValues() (Get-ChildItem -Path $PWD)[0].GetType().GetMethods() # List of all parameters that a given cmdlet supports along with a short description:: Get-Help dir -para '*' | Format-Table Name, { $PSItem.Description[0].Text } -wrap # List all loaded session modules and the exposed cmdlets / functions in them: Get-Module -Name '*' | ForEach-Object { Get-Command -Module $PSItem } | Out-GridView -PassThru -Title 'Available loaded modules and their cmdlets / functions' # Get a list of specific cmdlets/functions in a module: (Get-Module -Name 'PSReadline' -All).ExportedCommands | Out-GridView -PassThru -Title "Available loaded modules and their cmdlets / functions"