The PowerShell profile is a PowerShell script file (named profile.ps1 or Microsoft.PowerShell_profile.ps1)
that creates the PowerShell environment every time Windows PowerShell
is started. It can include aliases, PowerShell functions, or any other
type of PowerShell modifications you want.
Tip
The default location of the user’s PowerShell
profile is
C:\Users\username\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1.
However, it doesn’t exist by default.
You can view the location and name of the profile using the $profile variable executed at the PowerShell prompt as follows:
PS C:\> $profile
C:\Users\Darril\Documents\WindowsPowerShell\
Microsoft.PowerShellISE_profile.ps1
It’s important to realize that even though the $profile
points to this file and this location, it doesn’t mean the file
actually exists. The steps in the following table show how to test for
and create a profile used for the current user.
Note
You can also modify the profile with Notepad or the Windows PowerShell Integrated Scripting Environment . These steps use Notepad.
PowerShell Command | Comments |
---|
PS C:\> $profile C:\Users\Darril\Documents\ WindowsPowerShell\Microsoft. PowerShellISE_profile.ps1
| Displays the path and name of the profile. |
PS C:\> test-path $profile
| The test-path cmdlet identifies if the path exists. Returns true if it exists and false if not. |
PS C:\> new-item -path $profile -type file -force
| The new-item cmdlet creates the path and the profile file identified in the $profile variable. If test-path $profile returned false before, it will return true now.
Note
The -force switch overwrites the profile file, if one exists.
|
| Opens
the profile file with Notepad. If it was just created, it will be
blank. At this point, you can modify the profile as desired. |
Both local and global PowerShell profiles can exist. The following table compares these two profiles.
Global and Local Profiles | Comments |
---|
Global profile
C:\windows\system32\ WindowsPowerShell\v1.0\profile.ps1
Open with:
PS C:\> notepad c:\windows\system32\ WindowsPowerShell\v1.0\profile.ps1
| If a global profile exists, it is used for all users.
Note
Even though the path includes “v1.0,” this profile does apply to Windows PowerShell v2, which is installed on Windows 2008 R2.
|
Local profile
c:\users\username\documents\ windowspowershell\ microsoft.powershell_profile.ps1
Open with:
| Applies to currently logged-on user and takes precedence over global profile. The $profile variable holds the path for the local profile.
Tip
If PowerShell profiles exist in both locations, the local profile takes
precedence over the global profile if there are any conflicts. For
example, if the global profile sets the location to c:\data, but the
local profile sets the location to c:\scripts, the location would be
set to c:\scripts.
|