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

标签 powershell syntax alias

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/

相关文章:

azure - 备份 Azure 数据库时如何备份事务日志?

syntax - 学习位操作时的 "0xXXXX"语法是什么? (其中 X 是大写字母数字字符)

java - Android Studio 的 .alias 文件类型?

postgresql - 如何在 PostgreSQL 中创建一个新函数作为另一个函数的别名?

powershell - 找不到类型[cultureinfo]

Powershell CREDSSP 和 TLS 1.2

c# - 从 C# 自定义 Cmdlet 中调用读取主机 cmdlet

c - void *(*routine)(void *) 在 C 中是什么意思?

php - 脚本中出现意外的 ';'.. 但是当我删除 T_STRING 错误时

python .bash_profile 别名