Skip to content

Portable Powershell Profile

In some environments with tight Execution Policies you might find trouble when opening a Powershell session in which you have setup your own profile configuration.

You might be facing an error such as the one below.

. : File C:\Users\USERNAME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded because the execution of scripts is disabled on this system. For more information, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170
At line:1 char:3
+ . 'C:\Users\USERNAME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'
+
    + CategoryInfo : SecurityError: (:) [], PSSecurityException

The about_Execution_Policies link referenced in the above message describes the different Policies available and how to set them.

You might not be able to change the Execution Policy of the system in all scenarios, but you can nevertheless run a custom PowerShell session with a different Execution Policy by invoking powershell in the following way:

powershell.exe -ExecutionPolicy RemoteSigned -NoProfile -NoExit -Command ". profile.ps1"

You can create a Windows shortcut to run powershell in this way, placed next to your custom profile.ps1 configuration so you can have a portable profile with any customizations you'd prefer. If you set the "Start in" field of the shotcut to %CD%, then the starting directory will be the one where the shortcut is placed, so you won't need to set the path of the profile file.

The powershell session will run with RemoteSigned Policy and load the profile located in profile.ps1 (instead of the default profile) before opening an interactive command prompt.

Personal page