Martin Hollingsworth
Martin Hollingsworth

Reputation: 7329

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

Upvotes: 12

Views: 38990

Answers (6)

wraiford
wraiford

Reputation: 641

in 2024, "safer" option than other answers

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser 

explanation

I just wanted my profile to execute and it wouldn't. The other answers either didn't apply to me or were setting it to Unrestricted. Here is the official documentation on RemoteSigned:

  • The default execution policy for Windows server computers.
  • Scripts can run.
  • Requires a digital signature from a trusted publisher on scripts and configuration files that are downloaded from the internet which includes email and instant messaging programs.
  • Doesn't require digital signatures on scripts that are written on the local computer and not downloaded from the internet.
  • Runs scripts that are downloaded from the internet and not signed, if the scripts are unblocked, such as by using the Unblock-File cmdlet.
  • Risks running unsigned scripts from sources other than the internet and signed scripts that could be malicious.

Upvotes: 0

KMushonga
KMushonga

Reputation: 21

Use:

Set-ExecutionPolicy Unrestricted -Scope CurrentUser

Then reboot your PC.

Final Result

Upvotes: 2

Forever
Forever

Reputation: 31

I want to use the defualt profile, but I got a same question.

I have changed the executionplicy to solve the problem.

Set-ExecutionPolicy Unrestricted

[link] https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7.2

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2

Upvotes: 3

JAYAKUMAR SINNAPILLAI
JAYAKUMAR SINNAPILLAI

Reputation: 51

Delete both files

C:\Users\MyUserName\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1
C:\Users\MyUserName\Documents\WindowsPowerShell\profile.ps1

Upvotes: 5

Martin Hollingsworth
Martin Hollingsworth

Reputation: 7329

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.

Upvotes: 22

BartekB
BartekB

Reputation: 8650

Actually, that looks like AppLocker error message. Some information about it can be found here (however author is doing reverse - he tries to limit script usage).

If other profiles work (other than profile.ps1) that it may be just a deny rule.

Upvotes: 0

Related Questions