Windows PowerShell Profiles
To retain these changes, you can create a Windows PowerShell profile and add the aliases, functions, and variables to the profiles. The profile is loaded every time that Windows PowerShell starts.
To load a profile, your Windows PowerShell execution policy must permit you to load configuration files. If it does not, the attempt to load the profile fails and Windows PowerShell displays an error message.
Understanding the Profiles
- %windir%system32WindowsPowerShellv1.0profile.ps1
This profile applies to all users and all shells.
- %windir%system32WindowsPowerShellv1.0 Microsoft.PowerShell_profile.ps1
This profile applies to all users, but only to the Microsoft.PowerShell shell.
- %UserProfile%My DocumentsWindowsPowerShellprofile.ps1
This profile applies only to the current user, but affects all shells.
- %UserProfile%My DocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1
This profile applies only to the current user and the Microsoft.PowerShell shell.
Creating a Profile
To save the variables, aliases, functions, and commands that you use routinely, and make them available in every Windows PowerShell session, add them to your Windows PowerShell profile.
You can also create, share, and distribute profiles to enforce a consistent view of Windows PowerShell in a larger enterprise.
Windows PowerShell profiles are not created automatically. To create a profile, create a text file with the specified name in the specified location. Typically, you will use the user-specific, shell-specific profile, known as the Windows PowerShell user profile. The location of this profile is stored in the $profile variable.
To display the path to the Windows PowerShell profile, type:
To determine whether a Windows PowerShell profile has been created on the system, type:
If the profile exists, the response is True; otherwise, it is False.
To create a Windows PowerShell profile file, type:
To open the profile in Notepad, type:
To create one of the other profiles, such as the profile that applies to all users and all shells, type:
The profile is effective only when the file is located exactly in the path and with the file name that is stored in the $profile variable. Therefore, if you create a profile in Notepad and then save it, or if you copy a profile to
your system, be sure to save the file in the path and with the file name specified in the $profile variable.
If you create a profile in Notepad, enclose the file name in quotation marks to preserve the PS1 file name extension. For example:
Without the quotation marks, Notepad appends the .txt file name extension to the file, and Windows PowerShell will not recognize it.
Use the profile to store the aliases, functions, and variables that you use routinely. One very helpful opens your user profile in your favorite text editor. For example, the following command creates a function called pro that opens the user profile in Notepad.
A well-designed profile can make it even easier to use Windows PowerShell and to administer your system.
$env:UserProfileMy DocumentsWindowsPowerShellMicrosoft.PowerShellISE_profile.ps1
$env:windirsystem32WindowsPowerShellv1.0Microsoft.PowerShellISE_profile.ps1