A PowerShell profile is a PowerShell script that runs automatically when a new PowerShell session is started. PowerShell profiles can be used to configure your PowerShell environment the way you like it, or to load custom functions for use in your PowerShell administration tasks.
There are actually six PowerShell profiles relating to the PowerShell console and the PowerShell ISE. You can see the four console-related profiles by running the following command:
PS C:\Users\Paul> $profile | Get-Member -MemberType NoteProperty | fl name,definition Name : AllUsersAllHosts Definition : System.String AllUsersAllHosts=C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1 Name : AllUsersCurrentHost Definition : System.String AllUsersCurrentHost=C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1 Name : CurrentUserAllHosts Definition : System.String CurrentUserAllHosts=C:\Users\Paul\Documents\WindowsPowerShell\profile.ps1 Name : CurrentUserCurrentHost Definition : System.String CurrentUserCurrentHost=C:\Users\Paul\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
The two additional ISE-related profiles are:
- Current User, Current Host – ISE: $Home\[My ]Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1
- All Users, Current Host – ISE: $PsHome\Microsoft.PowerShellISE_profile.ps1
For the purposes of this article I will be referring to the Current User, Current Host profile.
You can check for an existing PowerShell profile by using Test-Path.
PS C:\> Test-Path $profile False
If there is no existing profile create one with New-Item.
PS C:\> New-Item $profile -ItemType File -Force Directory: C:\Users\Paul\Documents\WindowsPowerShell Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 29/09/2014 2:30 PM 0 Microsoft.PowerShell_profile.ps1
You can now edit the profile script using the PowerShell ISE or your PowerShell editor of choice and add custom functions and any other customizations that you require for your PowerShell console sessions.
PS C:\> powershell_ise.exe $profile
Examples:
This article PowerShell Tip: Create a PowerShell Profile is © 2014 ExchangeServerPro.com
Get more Exchange Server tips at ExchangeServerPro.com