PowerShell says "execution of scripts is disabled on this system."
I am trying to run the a .cmd file that calls a PowerShell script from the command prompt, and I am getting the below error:
Management_Install.ps1 cannot be loaded because the execution of scripts is disabled on this system.
I have ran set-executionpolicy unrestricted
and when I run get-executionpolicy
from PowerShell I get unrestricted
back.
//Output from Powershell
PS C:UsersAdministrator> get-executionpolicy
Unrestricted
//Output from DOS
C:ProjectsMicrosoft.Practices.ESBSourceSamplesManagement PortalInstallScr
ipts>powershell .Management_Install.ps1 1
WARNING: Running x86 PowerShell...
File C:ProjectsMicrosoft.Practices.ESBSourceSamplesManagement PortalInstallScriptsManagement_Install.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:25
.Management_Install.ps1 <<<< 1
CategoryInfo : NotSpecified: (:) [], PSSecurityException
FullyQualifiedErrorId : RuntimeException
C:ProjectsMicrosoft.Practices.ESBSourceSamplesManagement PortalInstallScripts>pause
Press any key to continue . . .
The system is Windows Server 2008 R2.
What am I doing wrong?
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.
您可以通过在运行PowerShell时添加-ExecutionPolicy ByPass
来绕过此策略
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 7 , Windows 8 , Windows Server 2008 R2 or Windows Server 2012 , run the following commands as Administrator :
x86 (32 bit)
Open C:WindowsSysWOW64cmd.exe
Run the command powershell Set-ExecutionPolicy RemoteSigned
x64 (64 bit)
Open C:Windowssystem32cmd.exe
Run the command powershell Set-ExecutionPolicy RemoteSigned
You can check mode using
echo %PROCESSOR_ARCHITECTURE%
[Environment]::Is64BitProcess
References:
MSDN - Windows PowerShell execution policies
Windows - 32bit vs 64bit directory explanation