7

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
Martin Hollingsworth
  • 7,249
  • 7
  • 49
  • 51

4 Answers4

21

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.

Martin Hollingsworth
  • 7,249
  • 7
  • 49
  • 51
  • 2
    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. – kkm inactive - support strike Mar 03 '15 at 00:28
5

Delete both files

C:\Users\MyUserName\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1
C:\Users\MyUserName\Documents\WindowsPowerShell\profile.ps1
Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
3

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

Forever
  • 31
  • 2
0

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.

BartekB
  • 8,492
  • 32
  • 33
  • 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. – Martin Hollingsworth Jun 11 '14 at 07:28
  • 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. – Martin Hollingsworth Jun 11 '14 at 07:36