$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
==============================================产品