PowerShell says "execution of scripts is disabled on this system." PowerShell says "execution of scripts is disabled on this system." powershell powershell

PowerShell says "execution of scripts is disabled on this system."


If you're using Windows Server 2008 R2 then there is an x64 and x86 version of PowerShell both of which have to have their execution policies set. Did you set the execution policy on both hosts?

As an Administrator, you can set the execution policy by typing this into your PowerShell window:

Set-ExecutionPolicy RemoteSigned

For more information, see Using the Set-ExecutionPolicy Cmdlet.

When you are done, you can set the policy back to its default value with:

Set-ExecutionPolicy Restricted

You may see an error:

Access to the registry key'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied. To change the execution policy for the default (LocalMachine) scope,   start Windows PowerShell with the "Run as administrator" option. To change the execution policy for the current user,   run "Set-ExecutionPolicy -Scope CurrentUser".

So you may need to run the command like this (as seen in comments):

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser


You can bypass this policy for a single file by adding -ExecutionPolicy Bypass when running PowerShell

powershell -ExecutionPolicy Bypass -File script.ps1


I had a similar issue and noted that the default cmd on Windows Server 2012, was running the x64 one.

For Windows 10, Windows 7, Windows 8, Windows Server 2008 R2 or Windows Server 2012, run the following commands as Administrator:

x86 (32 bit)
Open C:\Windows\SysWOW64\cmd.exe
Run the command powershell Set-ExecutionPolicy RemoteSigned

x64 (64 bit)
Open C:\Windows\system32\cmd.exe
Run the command powershell Set-ExecutionPolicy RemoteSigned

You can check mode using

  • In CMD: echo %PROCESSOR_ARCHITECTURE%
  • In Powershell: [Environment]::Is64BitProcess

References:
MSDN - Windows PowerShell execution policies
Windows - 32bit vs 64bit directory explanation