Profile scripts work like autostart scripts in PowerShell. They do not need to exist, but if they do, PowerShell executes its content silently during each launch. There are up to four profile scripts, and this line exposes their paths:
PS> $profile | Select-Object -Property *
AllUsersAllHosts : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShellISE_profile.ps1
CurrentUserAllHosts : C:\Users\tobia\OneDrive\Dokumente\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\tobia\OneDrive\Dokumente\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1
Length : 87
Don’t worry about the property “Length”: it is an artefact based on the fact that $profile is a string. PowerShell has added four properties to it returning the paths of the supported profile files.
Note that the profile paths for any profile containing “AllHosts” is the same for all PowerShell hosts. Anything you add to these execute in any host, including powershell.exe, PowerShell ISE, Visual Studio Code or PowerShell 7. The paths in properties containing “CurrentHost” are specific to the host where you execute this line.
All of these paths point to nowhere by default. To use one or more, make sure you create the file the path points to.
ReTweet this Tip!
Powered by IDERA