如何在 PowerShell 中使用 Alias 函式?
與 Parameter alias 類似,我們還可以設定函式別名名稱來以其他名稱引用函式。
示例
function Test-NewConnection{ [CmdletBinding()] [Alias("TC")] param( [Parameter(Mandatory=$true)] [String]$Server ) Write-Output "Testing $server connection" }
現在,除了 Test-NewConnection 函式名稱,還可以像下面顯示的那樣直接使用函式別名 “TC”。
PS C:\> Tc -Server "Test1-win2k16" Testing Test1-win2k16 connection
廣告