PowerShell: Profile (init file)

By Xah Lee. Date: . Last updated: .

What is PowerShell Profile

PowerShell profile are files PowerShell loads when starting up. It can contain your own functions, alias, or other customization.

Profile Location

Current user, Current Host

$Home\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

this is the most relevant to user.

Just create the file, and add Function or Alias or other PowerShell code to the file.

e.g. PowerShell: Color Prompt

Current User, All Hosts

$Home\Documents\PowerShell\Profile.ps1

All Users, Current Host

$PSHOME\Microsoft.PowerShell_profile.ps1

All Users, All Hosts

$PSHOME\Profile.ps1

Profile Path Variable

$profile is an Automatic Variables that stores Profile paths.

$profile
# C:\Users\xah\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

Note that even if this file does not exist, it still returns the path.

$profile is actually an object with many properties.

$profile | Get-Member -Type NoteProperty | Format-List

# TypeName   : System.String
# Name       : AllUsersAllHosts
# MemberType : NoteProperty
# Definition : string AllUsersAllHosts=C:\Program Files\PowerShell\7\profile.ps1

# TypeName   : System.String
# Name       : AllUsersCurrentHost
# MemberType : NoteProperty
# Definition : string AllUsersCurrentHost=C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1

# TypeName   : System.String
# Name       : CurrentUserAllHosts
# MemberType : NoteProperty
# Definition : string CurrentUserAllHosts=C:\Users\xah\Documents\PowerShell\profile.ps1

# TypeName   : System.String
# Name       : CurrentUserCurrentHost
# MemberType : NoteProperty
# Definition : string CurrentUserCurrentHost=C:\Users\xah\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

Start PowerShell Without Loading Profile

pwsh -NoProfile

Show PowerShell Command-Line Options

pwsh -h

or

pwsh -?

PowerShell. Profile and Script