我能用Windows PowerShell做什麼:建立一個新的 Windows PowerShell 別名
阿新 • • 發佈:2019-01-27
注:本篇文章,未在聯絡作者以及得到許可的情況下, 禁止以任何形式進行轉載。
建立一個新的 Windows PowerShell 別名你說你像Windows PowerShell,但你有些有關記住cmdlet名稱的問題?好,那麼為什麼不給那些cmdlets建立一個別名呢?你能記住一個別名。
舉個例子來說,也許你比較喜歡輸入一個能替代Get-ChildItem的命令,如果這麼說的話,那麼你可以使用New-Alias cmdlet 術語來對映顯示Get-ChildItem。你要做的只是使用New-Alias(顯示)並且將cmdlet對映到別名,指定(Get-ChildItem)。你都知道,類似於這樣:
現在,你推想下你下次輸入時會在Windows PowerShell控制檯裡顯示什麼?你會得到如下:
在預設情況下,別名不會在儲存在Windows PowerShell會話之中:每次你重新啟動Windows PowerShell你需要再建立一個別名。確保你的新別名存在於Windows PowerShell會話中。建立一個PSConfiguration資料夾在你的Windows PowerShell profile資料夾裡。
例如:
C:Documents and SettingsgstempMy DocumentsPSConfiguration注意:假設你想知道Windows PowerShell profile資料夾是怎麼樣的?那麼就輸入這個命令:
Get-Variable profile | Format-List在PSConfiguration資料夾中,建立一個檔名為microsoft.powershell_profile.ps1並新增以下命令檔案:
Set-Alias show Get-ChildItem那是應該做的伎倆。