Powershell Profiles配置文件的存放位置介绍
配置文件存放于如下几个地方,不同的配置文件,作用域不同。
1、%windir%\system32\WindowsPowerShell\v1.0\profile.ps1
它作用于所有用户、所有的Shell。
2、%windir%\system32\WindowsPowerShell\v1.0\ Microsoft.PowerShell_profile.ps1
作用于所有用户,但只作用于Microsoft.PowerShell这个shell。这个我也没懂是什么意思,难道还有不是PowerShell的PowerShell shell?呃,有点像绕口令。
3、%UserProfile%\My Documents\WindowsPowerShell\profile.ps1
作用于当前用户的所有shell。
4、%UserProfile%\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
作用于当前用户的Microsoft.PowerShell这个shell。
创建这个文件
New-Item -Path "C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.Powershell_profile.ps1" -ItemType file -Force
创建之后,
如果用 psedit $profile, 则默认会找C:\Users\allen\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1
这是因为:
Profile Type | Profile Path |
---|---|
“Current user, PowerShell ISE” |
$profile.CurrentUserCurrentHost, or $profile |
“All users, PowerShell ISE” |
$profile.AllUsersCurrentHost |
“Current user, All hosts” |
$profile.CurrentUserAllHosts |
“All users, All hosts” |
$profile.AllUsersAllHosts |
To create a new profile
To create a new “Current user, Windows PowerShell ISE” profile, run this command:
if (!(test-path $profile )) {new-item -type file -path $profile -force}
To create a new “All users, Windows PowerShell ISE” profile, run this command:
if (!(test-path $profile.AllUsersCurrentHost)) {new-item -type file -path $profile.AllUsersCurrentHost -force}
To create a new “Current user, All Hosts” profile, run this command:
if (!(test-path $profile.CurrentUserAllHosts)) {new-item -type file -path $profile.CurrentUserAllHosts -force}
To create a new “All users, All Hosts” profile, type:
if (!(test-path $profile.AllUsersAllHosts)) {new-item -type file -path $profile.AllUsersAllHosts-force}
To edit a profile
- To open the profile, run the command psedit with the variable that specifies the profile you want to edit. For example, to open the “Current user, Windows PowerShell ISE” profile, type:
psEdit $profile
-
Add some items to your profile. The following are a few examples to get you started:
-
To change the default background color of the Console Pane to blue, in the profile file type:
$psISE.Options.OutputPaneBackground = 'blue'
. For more information about the $psISE variable, see Windows PowerShell ISE Object Model Reference. -
To change font size to 20, in the profile file type:
$psISE.Options.FontSize =20
-
To change the default background color of the Console Pane to blue, in the profile file type:
- To save your profile file, on the File menu, click Save. Next time you open the Windows PowerShell ISE, your customizations are applied.
详情见: https://technet.microsoft.com/en-us/library/dd819434.aspx