powershell

Powershell profile.ps1 cannot be loaded because its operation is blocked by software restriction policies


When starting a PowerShell host (powershell.exe, PowerShellISE, NuGet Package Manager Console etc) I was getting the following error message.

File C:\Users\MyUserName\Documents\WindowsPowerShell\profile.ps1 cannot be loaded because its operation is blocked by software restriction policies. For more information, contact your system administrator.

This was particularly problematic in the case of the NuGet Package Manager Console as the console was left in a disabled / unusable state after the error. Other PowerShell hosts could at least be used.

I had problems a few weeks ago, when setting up my workstation at a new job, because a Group Policy setting was applying a MachinePolicy of AllSigned. That issue had been resolved by changing the setting to RemoteSigned. I checked that this setting is still in place using the command:

Get-ExecutionPolicy -List

I also confirmed that this $profile.CurrentUserAllHosts file exists but my Internet searches for another "Group Policy setting" revealed nothing of interest. My PowerShell version information is:

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      3.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.18408
BuildVersion                   6.2.8370.0
PSCompatibleVersions           {1.0, 2.0, 3.0}
PSRemotingProtocolVersion      2.2

Solution

  • If I delete or move the problem profile script then all of my PowerShell hosts start without errors, including the PowerShell ISE which was using it's own Current User Current Host script C:\Users\MyUserName\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1

    It turns out that the problem with my All Hosts profile script was that it was completely empty! Adding any content into the file, even a single space character or comment, allowed this profile script to be executed by all of the various PowerShell hosts. I must have cleared out the contents of this script at some point, instead of deleting it.

    Not exactly an intuitive error message which is why I'm posting this Q&A style entry for future reference.

    Interestingly, I am able to execute empty / blank scripts in all hosts after they have started and this problem seems to be specific to profile scripts.