Search notes:

PowerShell: The automatic variable $PROFILE

The value of the automatic variable $profile is the file name of a PowerShell profile for the current user and the current host application. This profile is executed automatically when PowerShell is started (unless PowerShell is invoked with the command line option -noProfile).

Type of $profile

The type of $profile seems to be a string:
PS C:\Users\Rene> $profile.getType().fullName
System.String

Four profile locations (Windows)

It turns out, though, that $profile is not a exactly a string as this variable actually stores four profile locations by means of the Extended Type System:
PS C:\Users\Rene> write-output $profile
C:\Users\Rene\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

PS C:\Users\Rene> write-output $profile.currentUserCurrentHost
C:\Users\Rene\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

PS C:\Users\Rene> write-output $profile.currentUserAllHosts
C:\Users\Rene\Documents\WindowsPowerShell\profile.ps1

PS C:\Users\Rene> write-output $profile.allUsersCurrentHost
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1

PS C:\Users\Rene> write-output $profile.allUsersAllHosts
C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
Note: host in this context does not refer to a computer or server, but rather to the program that is hosting PowerShell, compare with the cmdLet noun host.
The four profile location values can also be shown by piping the $profile «object» into format-list with the -force option or by explicitly asking for the psExtended member:
C:\> $profile | format-list -force
C:\> $profile.psExtended

PowerShell Core

Windows

In PowerShell core, on Windows, the directory name WindowsPowerShell is replaced with simply PowerShell, for example C:\Users\Rene\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

Linux

The values of $profile in Linux are:
  • /home/<username>/.config/powershell/Microsoft.PowerShell_profile.ps1
  • /home/<username>/.config/powershell/profile.ps1
  • /opt/microsoft/powershell/7/Microsoft.PowerShell_profile.ps1
  • /opt/microsoft/powershell/7/profile.ps1

See also

In order to bypass the execution of the profile file when PowerShell is started, it needs to be started with powershell.exe -noProfile.
If PowerShell is started without the command line option -noLogo and the execution of the profile script takes longer than a certain amount of time (I believe this threshold to be 500 ms), PowerShell will also display the message Loading personal and system profiles took xyz ms..
The profile is not executed if the execution policy is set to restricted.
Other automatic variables
This (simple) profile.ps1 script.
The profile is a good place to define default value in the $psDefaultParameterValues automatic variable.
The .profile file in bash.

Index