欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Windows Powershell 通過函數(shù)擴(kuò)展別名

 更新時(shí)間:2014年09月02日 16:35:28   投稿:hebedich  
這篇文章主要介紹了Windows Powershell 通過函數(shù)擴(kuò)展別名,需要的朋友可以參考下

在Powershell中設(shè)置別名的確方便快捷,但是在設(shè)置別名的過程中并設(shè)置參數(shù)的相關(guān)信息。盡管別名會(huì)自動(dòng)識別參數(shù),但是如何把經(jīng)常使用的參數(shù)默認(rèn)設(shè)定在別名里面呢?例如Test-Connection -Count 2 -ComputerName,讓-”-Count 2″ 固化在別名中。

這時(shí)簡單的別名無法完成上述需求,可以通過函數(shù)來完成它,并且一旦把函數(shù)拉過來,定義別名會(huì)變得更加靈活。

PS C:\PS> function test-conn { Test-Connection -Count 2 -ComputerName $args}
PS C:\PS> Set-Alias tc test-conn
PS C:\PS> tc localhost

Source    Destination   IPV4Address   IPV6Address               Bytes  Time(ms)
------    -----------   -----------   -----------               -----  --------
test-me-01  localhost    127.0.0.1    ::1                   32    0
test-me-01  localhost    127.0.0.1    ::1                   32    0

有了函數(shù)牽線,別名可以完成更高級更強(qiáng)大的功能,其中$args為參數(shù)的占位符,經(jīng)測試,發(fā)現(xiàn)這個(gè)占位符必須以$args命名,否則不能識別,會(huì)拋出異常:
Cannot validate argument on parameter ‘ComputerName'. The argument is null or empty. Supply an arg
nt that is not null or empty and then try the command again.

相關(guān)文章

最新評論