Understanding Profile Scripts

by Jul 11, 2013

Whenever you want PowerShell to configure or execute code automatically on launch, the code needs to go into one of four profile scripts. They really work pretty much like autoexec.bat for Windows in old days, and execute whenever PowerShell starts.

You can find the path to your primary profile script in $profile variable. It may look similar to this:

This is a user-specific and host-specific path, so it only works for you, and it only works for the current PowerShell host (in this case my ISE editor). It will not execute in other hosts.

To turn this into a host-independent script, simply remove the host name part (in this case "Microsoft.PowerShellISE_", or try this:

As you see, there is a host-independent generic profile and a host-specific profile, and while Microsoft ships two hosts (PowerShell and PowerShellISE), there can be more like PowerShell Plus, PowerGUI, or others.

To turn a profile into a user-independent profile, it must reside in the PowerShell system folder:

Twitter This Tip! ReTweet this Tip!