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.
|Current user and host||$HOME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1|
|Current user, all hosts||$HOME\Documents\WindowsPowerShell\profile.ps1|
|All users, current host||$PSHOME\Microsoft.PowerShell_profile.ps1|
|All users, all hosts||$PSHOME\profile.ps1|
|Current user and host in ISE||$HOME\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1|
|All users, current host ISE||$PSHOME\Microsoft.PowerShellISE_profile.ps1|
Typically you will use the profile for the current user and host which is stored in file $HOME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 that is referenced through $profile. An easy way to create this profile is:
#Check if exists Test-Path $profile #Create if does not exist New-Item -Path $profile -ItemType file -Force #Then edit in notepad Notepad $profile