Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring multiple aliases in an advanced PowerShell function

The documentation for declaring aliases in PowerShell cmdlets shows the following:

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

    Get-WmiObject -Class Win32_ComputerSystem -ComputerName $ComputerName
}

What syntax do I use to create multiple aliases?

  • [Alias("one","two","three)]
  • [Alias("one")][Alias("two")][Alias("three")]
  • None of the above
  • Something else?

P.S. When using Get-Help, where are the aliases supposed to be shown? So far I don't see them.

like image 818
ChiliYago Avatar asked Oct 19 '25 10:10

ChiliYago


1 Answers

[Alias("one")][Alias("two")] and [Alias("one", "two")] both work. You see the aliases when you display the help for the parameter:

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
like image 100
Ansgar Wiechers Avatar answered Oct 22 '25 04:10

Ansgar Wiechers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!