A Powershell profile is a script file that is run each time a new Powershell is opened.
You can define session-specific items in it (variables, aliases, functions, etc.) or call other scripts and commands at the start of a new Powershell session.
General Notes
-
Variables defined in a profile file become automatically and always global variables (
$global:...
) in the Powershell session that begins.
My attempts to limit the scope and lifetime of such internal variables (by trying$local:...
,$script:...
or$private:..
) weren’t successful 😞 -
For reference: A backup of my own profile is saved here.
Types, Names, Locations
Profile files are expected to be found under specific locations, with specific filenames (see below).
On this page, only the Microsoft Windows paths are listed; paths for Linux or MacOS can be found in the official
Powershell profile documentation.
I have omitted variables and paths specific to the PowerShell ISE (never used it much; no longer under active development).
The order in which the profile scripts are executed can also be important:
A profile that is applied at a later stage (e.g. 4) overrides a value that was set at an earlier stage (e.g. 1).
Windows Powershell (until v5.1, windows-only)
Order | Profile Type | Predefined variable | Location and filename |
---|---|---|---|
1 | All Users & All Hosts | $PROFILE.AllUsersAllHosts | $PSHome\profile.ps1 |
2 | All Users & Current Host | $PROFILE.AllUsersCurrentHost | $PSHome\Microsoft.PowerShell_profile.ps1 |
3 | Current User & All Hosts | $PROFILE.CurrentUserAllHosts | $Home\Documents\WindowsPowerShell\profile.ps1 |
4 | Current User & Current Host | $PROFILE.CurrentUserCurrentHost (= $PROFILE) | $Home\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 |
Powershell (since v6.0, cross-platform)
Order | Profile Type | Predefined variable | Location and filename |
---|---|---|---|
1 | All Users & All Hosts | $PROFILE.AllUsersAllHosts | $PSHome\profile.ps1 |
2 | All Users & Current Host | $PROFILE.AllUsersCurrentHost | $PSHome\Microsoft.PowerShell_profile.ps1 |
3 | Current User & All Hosts | $PROFILE.CurrentUserAllHosts | $Home\Documents\PowerShell\profile.ps1 |
4 | Current User & Current Host | $PROFILE.CurrentUserCurrentHost (= $PROFILE) | $Home\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 |
Starting a Powershell without a profile
Sometimes you need to start a fresh and clean Powershell, without any setup; for that, call the Powershell executable with the -NoProfile parameter:
powershell -NoProfile # "Windows Powershell" (up to v5.1)
pwsh -NoProfile # "Powershell" (since v6)
Film & Television (54)
How To (63)
Journal (17)
Miscellaneous (4)
News & Announcements (21)
On Software (12)
Projects (26)