Saving PowerShell User Defaults

by Sep 9, 2016

We are about to enter “Color Week” with plenty of tips how you can choose better colors for the PowerShell ISE editor and the console. Most changes that you apply to PowerShell are not saved. PowerShell ISE does save some of the color settings, but a more robust way is to place your customizations in one of PowerShell’s profile scripts.

Anything that should be run for any PowerShell host (console as well as PowerShell ISE or any other PowerShell-enabled program) goes here:

PS C:\> $profile.CurrentUserAllHosts

Anything that applies to a specific host like the console only, or the PowerShell ISE only, goes here:

PS C:\>  $profile.CurrentUserCurrentHost

Note the “XXX” in the path. You need to run the above line inside the host you want to target. The line returns different paths, depending on the host you are running.

Note also that these calls just provide the path to the profile script. It does not exist by default. You may have to create it, along with the folder “WindowsPowerShell”. When the profile script does exist, it is executed whenever a PowerShell host is launched.

Just make sure script execution is turned on. So you may have to one-time enable script execution, for example like this:

PS> Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force 

Twitter This Tip! ReTweet this Tip!