I am trying to run a cmd file that calls a PowerShell script from cmd.exe, but I am getting this error:
cmd
cmd.exe
Management_Install.ps1 cannot be loaded because the execution of scripts is disabled on this system.
Management_Install.ps1
I ran this command:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
When I run Get-ExecutionPolicy from PowerShell, it returns Unrestricted.
Get-ExecutionPolicy
Unrestricted
Output:
cd “C:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts” powershell .\Management_Install.ps1 1 WARNING: Running x86 PowerShell… File C:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts\Management_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:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts> PAUSE Press any key to continue . . .
cd “C:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts” powershell .\Management_Install.ps1 1
WARNING: Running x86 PowerShell…
File C:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts\Management_Install.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see “get-help about_signing” for more details.
C:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts\Management_Install.ps1
get-help about_signing
At line:1 char:25
.\Management_Install.ps1
C:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts> PAUSE
Press any key to continue . . .
The system is Windows Server 2008 R2.
What am I doing wrong?
If you’ve set the execution policy to Unrestricted using Set-ExecutionPolicy, and you’re still encountering the issue, it’s possible that the policy is being overridden by a more restrictive policy or a Group Policy.
Set-ExecutionPolicy
Here are some steps to troubleshoot and resolve the issue:
Run as Administrator
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine
Get-ExecutionPolicy -List
If a Group Policy is present, you might need to contact your system administrator to adjust it.
$env:PROCESSOR_ARCHITECTURE
If it returns “x86,” you are running the 32-bit version. If it returns “AMD64” or “x64,” you are running the 64-bit version.
If the issue persists, try running the 64-bit version explicitly:
%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe
RemoteSigned
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Ensure that the PowerShell script is not blocked by Windows. Right-click on the script file, go to Properties, and click on Unblock if the option is present.
Properties
Unblock
After checking these aspects, try running your script again. If the issue persists, you might need to investigate other security policies or antivirus software that could be affecting script execution on your system.