如何将别名用于 PowerShell 中的参数?


PowerShell 别名是一种以别名使用参数快捷名称的好方法,而无需写出参数的全名。例如,你可以将服务器作为服务器名称,AppID作为应用程序 ID

因此,你不必使用参数的全名,而且也很容易记住。

示例

function Aliastest{
   param(
      [parameter(Mandatory=$true)]
      [Alias("Server")]
      [string]$ServerName
   )
   Write-Output "Server name is $ServerName"
}

现在,我们可以在传递参数时使用服务器而不是服务器名称。

PS C:\> Aliastest -server "Test1-Win2k16"
Server name is Test1-Win2k16

更新时间:2020 年 11 月 9 日

3K+ 浏览量

为你的职业生涯开启新篇章

修完课程获得认证

开始学习
广告
© . All rights reserved.