$pshome :powershell的主目錄
$profile :顯示 Windows PowerShell 配置文件的路徑
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 外殼。
啟動時按順序加載,最后一個優先級最高,會覆蓋之前的配置文件
這些配置文件並不是在默認情況下創建的。必須在您手動創建后,它們才會出現。
例,創建適用於所有用戶和所有 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:路徑下,還會自動加載函數 pp
==============================================