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

20,753

Solution 1

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.

Solution 2

Delete both files

C:\Users\MyUserName\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1
C:\Users\MyUserName\Documents\WindowsPowerShell\profile.ps1
Share:
20,753
ANISH S NAIR
Author by

ANISH S NAIR

Full stack (code and infrastructure) Tech Lead

Updated on July 25, 2022

Comments

  • ANISH S NAIR
    ANISH S NAIR 5 months

    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
    
  • ANISH S NAIR
    ANISH S NAIR over 8 years
    Perhaps my answer is not clear but the problem goes away when I add any content to the profile. In other words I have a solution and my Q&A is to document the solution. For your information, other profiles exhibit the same behaviour.
  • ANISH S NAIR
    ANISH S NAIR over 8 years
    Out of curiosity (I haven't heard about AppLocker before) I checked my system and confirmed that there are no Script Rules configured for my machine.
  • kkm
    kkm almost 8 years
    Actually, attempting to run an empty file like powershell empty.ps1 causes same error message! When I simply added a single # character to the file, the error went away. Looks like this is simply a misleading error message.
  • MaylorTaylor
    MaylorTaylor 10 months
    This solved my problem instantly.