documentation在 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
}
我使用什么语法来创建多个别名?
[别名("one","two","three)]
[Alias("one")][Alias("two")][Alias("three")]
- 以上都不是
- 还有别的吗?
附言使用 Get-Help
时,应该在哪里显示别名?到目前为止,我还没有看到它们。
最佳答案
[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
关于powershell - 在高级 PowerShell 函数中声明多个别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51071800/