在高级PowerShell函数中声明多个别名

Chi*_*ago 3 syntax powershell alias

在PowerShell cmdlet中声明别名的文档显示以下内容:

Function Get-SomeValue {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0)]
        [Alias("MachineName")]
        [string[]]$ComputerName
    )

    Get-WmiObject -Class Win32_ComputerSystem -ComputerName $ComputerName
}
Run Code Online (Sandbox Code Playgroud)

我用什么语法来创建多个别名?

  • [Alias("one","two","three)]
  • [Alias("one")][Alias("two")][Alias("three")]
  • 以上都不是
  • 别的什么?

PS使用时Get-Help,应该显示别名在哪里?到目前为止,我没有看到它们.

Ans*_*ers 5

[Alias("one")][Alias("two")][Alias("one", "two")]两个工作.当您显示参数的帮助时,您会看到别名:

PS C:\> Get-Help Get-SomeValue -Parameter computername

-ComputerName <string[]>

    Required?                    true
    Position?                    0
    Accept pipeline input?       true (ByValue)
    Parameter set name           (All)
    Aliases                      one, two
    Dynamic?                     false