A PowerShell profile is a script that runs when PowerShell starts. You can use the profile as a logon script to customize the environment. You can add commands, aliases, functions, variables, snap-ins, modules, and PowerShell drives. You can also add other session-specific elements to your profile so they are available in every session without having to import or re-create them.
You can create a PowerShell profile to customize your environment and to add session-specific elements to every PowerShell session that you start.
PowerShell supports several profile files. Also, PowerShell host programs can support their own host-specific profiles.
For example, the PowerShell console supports the following basic profile files. The profiles are listed in precedence order. The first profile has the highest precedence.
| Description | Path |
|---|---|
| All Users, All Hosts | $PSHOME\Profile.ps1 |
| All Users, Current Host | $PSHOME\Microsoft.PowerShell_profile.ps1 |
| Current User, All Hosts | $Home\[My ]Documents\PowerShell\Profile.ps1 |
| Current user, Current Host | $Home\[My ]Documents\PowerShell\ Microsoft.PowerShell_profile.ps1 |
The profile paths include the following variables:
$PSHOME variable, which stores the installation directory for
PowerShell$Home variable, which stores the current user's home directoryIn addition, other programs that host PowerShell can support their own profiles. For example, Visual Studio Code supports the following host-specific profiles.
| Description | Path |
|---|---|
| All users, Current Host | $PSHOME\Microsoft.VSCode_profile.ps1 |
| Current user, Current Host | $Home\[My ]Documents\PowerShell\ Microsoft.VSCode_profile.ps1 |
The $PROFILE automatic variable stores the paths to the PowerShell profiles
that are available in the current session.
To view a profile path, display the value of the $PROFILE variable. You can
also use the $PROFILE variable in a command to represent a path.
The $PROFILE variable stores the path to the "Current User, Current Host"
profile. The other profiles are saved in note properties of the $PROFILE
variable.
For example, the $PROFILE variable has the following values in the Windows
PowerShell console.
| Description | Name |
|---|---|
| Current User, Current Host | $PROFILE |
| Current User, Current Host | $PROFILE.CurrentUserCurrentHost |
| Current User, All Hosts | $PROFILE.CurrentUserAllHosts |
| All Users, Current Host | $PROFILE.AllUsersCurrentHost |
| All Users, All Hosts | $PROFILE.AllUsersAllHosts |
Because the values of the $PROFILE variable change for each user and in each
host application, ensure that you display the values of the profile variables
in each PowerShell host application that you use.
To see the current values of the $PROFILE variable, type:
$PROFILE | Get-Member -Type NoteProperty
To create a PowerShell profile, use the following command format:
if (!(Test-Path -Path <profile-name>)) { New-Item -ItemType File -Path <profile-name> -Force }
For example, to create a profile for the current user in the current PowerShell host application, use the following command:
if (!(Test-Path -Path $PROFILE)) { New-Item -ItemType File -Path $PROFILE -Force }
In this command, the If statement prevents you from overwriting an existing
profile. Replace the value of the <profile-path> placeholder with the path
to the profile file that you want to create.
Note
To create "All Users" profiles in Windows Vista and later versions of Windows, start PowerShell with the Run as administrator option.
You can open any PowerShell profile in a text editor, such as Notepad.
To open the profile of the current user in the current PowerShell host application in Notepad, type:
notepad $PROFILE
To open other profiles, specify the profile name. For example, to open the profile for all the users of all the host applications, type:
notepad $PROFILE.AllUsersAllHosts
To apply the changes, save the profile file, and then restart PowerShell.
If you use multiple host applications, put the items that you use in all the
host applications into your $PROFILE.CurrentUserAllHosts profile. Put items
that are specific to a host application, such as a command that sets the
background color for a host application, in a profile that is specific to that
host application.
If you are an administrator who is customizing PowerShell for many users, follow these guidelines:
$PROFILE.AllUsersAllHosts profile$PROFILE.AllUsersCurrentHost profiles that are specific to the host
applicationBe sure to check the host application documentation for any special implementation of PowerShell profiles.
Many of the items that you create in PowerShell and most commands that you run affect only the current session. When you end the session, the items are deleted.
The session-specific commands and items include variables, preference variables, aliases, functions, commands (except for Set-ExecutionPolicy), and PowerShell modules that you add to the session.
To save these items and make them available in all future sessions, add them to a PowerShell profile.
Another common use for profiles is to save frequently-used functions, aliases, and variables. When you save the items in a profile, you can use them in any applicable session without recreating them.
When you open the profile file, it is blank. However, you can fill it with the variables, aliases, and commands that you use frequently.