Create a Powershell profile
- By : Dom
- Category : Scripting
- Tags: Powershell

A Powershell profile launches when you start Powershell. Bascially a profile is a function runs each time you open a Powershell session. As there are different ways to open Powershell (console, Powershell ISE, 3rd party app) , there are different profiles you can create. The profile is a feature of the host applications and not of the Powershell engine. The different profiles are stored in different locations so can contain different code. There is also a different order in which they are loaded. None of these script files exist by default, and not all the directory paths exist by default. Profile scripts are loaded in the order shown here, and are loaded only if the directory path and file exists when the shell session is started.
Profile Script Purpose | Console host application | ISE host application |
---|---|---|
Current user, current host | $home\Documents\WindowsPowerShell \Microsoft.PowerShell_profile.ps1 | $home\Documents\WindowsPowerShell \Microsoft.PowerShellISE_profile.ps1 |
Current user, all hosts | $home\Documents\WindowsPowerShell \Profile.ps1 | $home\Documents\WindowsPowerShell \Profile.ps1 |
All users, current host | $pshome\Microsoft.PowerShell_profile.ps1 | $pshome\Microsoft.PowerShellISE_profile.ps1 |
All users, all hosts | $pshome\Profile.ps1 | $pshome\Profile.ps1 |
Creating a (current) user Profile
Launch powershell.
Check if you already have a Powershell profile enter:
1 |
Test-Path $Profile |
If it returns ‘True’ then you have a powershell profile if ‘false’ then we can create a by typing:
1 |
New-Item –Path $Profile –Type File –Force |
We can now edit the profile. Either navgiate to “C:\Users\<username>\Documents\WindowsPowershell\Microsoft.Powershell_profile.ps1
or we can launch notepad from Powershell and edit:
1 |
notepad $profile |
No Comments