Configure commands to run when opening PowerShell instancesConfigure commands to run when opening PowerShell instances

Learn the best way to run commands when launching new PowerShell instances.

John Savill

March 11, 2016

1 Min Read
Configure commands to run when opening PowerShell instances

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

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like