Skip to content

/config/powershell/powershell-profile

$PROFILE: where the PowerShell profile is and how to create it

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
PowerShell
file
$PROFILE (Microsoft.PowerShell_profile.ps1 in the user's Documents folder)
key
$PROFILE.CurrentUserCurrentHost
type
path to a .ps1 script run at startup
default
not created; Documents\WindowsPowerShell\ (5.1) or Documents\PowerShell\ (7)

A PowerShell profile is a script that runs every time PowerShell starts, used for aliases, functions, prompt changes and module imports. $PROFILE holds the path of the most common one, current user, current host. The file does not exist until you create it:

powershell
if (-not (Test-Path $PROFILE)) { New-Item -Path $PROFILE -ItemType File -Force }
notepad $PROFILE

-Force also creates the missing WindowsPowerShell or PowerShell folder. Changes take effect in new sessions, or immediately after . $PROFILE.

The four profiles

$PROFILE also has a property for each of the four profile paths:

powershell
$PROFILE.PSObject.Properties | Where-Object Name -like '*Host*' | ForEach-Object {
  '{0,-24} {1}' -f $_.Name, (Split-Path $_.Value -Leaf)
}
"CurrentUserCurrentHost is in a folder named: $(Split-Path (Split-Path $PROFILE -Parent) -Leaf)"

Output

AllUsersAllHosts         profile.ps1
AllUsersCurrentHost      Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts      profile.ps1
CurrentUserCurrentHost   Microsoft.PowerShell_profile.ps1
CurrentUserCurrentHost is in a folder named: WindowsPowerShell
PropertyWindows PowerShell 5.1PowerShell 7 (Windows)
CurrentUserCurrentHost ($PROFILE)Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1Documents\PowerShell\Microsoft.PowerShell_profile.ps1
CurrentUserAllHostsDocuments\WindowsPowerShell\profile.ps1Documents\PowerShell\profile.ps1
AllUsersCurrentHost$PSHOME\Microsoft.PowerShell_profile.ps1$PSHOME\Microsoft.PowerShell_profile.ps1
AllUsersAllHosts$PSHOME\profile.ps1$PSHOME\profile.ps1

"Host" is the program that hosts PowerShell: the console, the VS Code PowerShell extension (Microsoft.VSCode_profile.ps1) and the ISE (Microsoft.PowerShellISE_profile.ps1) each have their own current-host profile. Put settings for all of them in CurrentUserAllHosts.

On Linux and macOS, PowerShell 7 uses ~/.config/powershell/Microsoft.PowerShell_profile.ps1.

Things that surprise people

  • OneDrive folder redirection: when OneDrive backs up Documents, the profile path is under OneDrive\Documents\.... Always use $PROFILE instead of a typed path.
  • 5.1 and 7 have separate profiles. A profile in WindowsPowerShell is not read by pwsh, and the reverse.
  • Execution policy: the profile is a script, so with the Restricted policy it fails to load with running scripts is disabled on this system.
  • Skip it: powershell -NoProfile (or pwsh -NoProfile) starts without any profile. Scripts run by scheduled tasks and CI should use it, so they do not depend on a user's profile.

Sources