Configure commands to run when opening PowerShell instances
Learn the best way to run commands when launching new PowerShell instances.
March 11, 2016
![Configure commands to run when opening PowerShell instances Configure commands to run when opening PowerShell instances](https://eu-images.contentstack.com/v3/assets/blt07f68461ccd75245/blt19ebfd0ee27f5592/661809b7b8fe8d114b09cbcb/powershell_4_0_5.jpg?width=850&auto=webp&quality=95&format=jpg&disable=upscale)
Q. How can I configure commands to run when opening a PowerShell instance?
A. There are a number of ways to run commands when launching a PowerShell instance such as changing the command shortcut however the better option is to utilize a PowerShell profile that contains commands that will be executed when a new PowerShell instance is launched. There are actually 6 different PowerShell profiles available however typically you will use only one. The six profiles are listed below in addition to when they are used.
Profile | Path |
Current user and host | $HOMEDocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1 |
Current user, all hosts | $HOMEDocumentsWindowsPowerShellprofile.ps1 |
All users, current host | $PSHOMEMicrosoft.PowerShell_profile.ps1 |
All users, all hosts | $PSHOMEprofile.ps1 |
Current user and host in ISE | $HOMEDocumentsWindowsPowerShellMicrosoft.PowerShellISE_profile.ps1 |
All users, current host ISE | $PSHOMEMicrosoft.PowerShellISE_profile.ps1 |
Typically you will use the profile for the current user and host which is stored in file $HOMEDocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1 that is referenced through $profile. An easy way to create this profile is:
#Check if existsTest-Path $profile#Create if does not existNew-Item -Path $profile -ItemType file -Force #Then edit in notepadNotepad $profile
About the Author(s)
You May Also Like