$pshome :powershell的主目錄shell
$profile :顯示 Windows PowerShell 配置文件的路徑api
test-path $profile :肯定是否已經在系統上建立了 Windows PowerShell 配置文件函數
powershell.exe 主機配置文件(在 Windows Vista 中)的位置以下所示:
%windir%\system32\WindowsPowerShell\v1.0\profile.ps1 用於計算機的全部用戶和全部外殼。
%windir%\system32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1 用於計算機的全部用戶,但僅用於 Microsoft.PowerShell 外殼。
%UserProfile%\Documents\WindowsPowerShell\profile.ps1 僅用於當前用戶和全部外殼。
%UserProfile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 僅用於當前用戶和 Microsoft.PowerShell 外殼。工具
啓動時按順序加載,最後一個優先級最高,會覆蓋以前的配置文件
這些配置文件並非在默認狀況下建立的。必須在您手動建立後,它們纔會出現。spa
例,建立適用於全部用戶和全部 shell 的配置文件,鍵入:
new-item -path $env:windir\System32\WindowsPowerShell\v1.0\profile.ps1 -itemtype file -force
notepad $env:windir\System32\WindowsPowerShell\v1.0\profile.ps1
如輸入:
c:
cd c:\
function pp
{
write-host "ppc"
}
編輯後保存,而後再從新運行powershell.exe,會加載profile.ps1中的內容,在啓動後會自動跳轉到C:路徑下,還會自動加載函數 pporm
==============================================產品