小能豆

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

javascript

I am trying to run a cmd file that calls a PowerShell script from cmd.exe, but I am getting this error:

Management_Install.ps1 cannot be loaded because the execution of scripts is disabled on this system.

I ran this command:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

When I run Get-ExecutionPolicy from PowerShell, it returns Unrestricted.

Get-ExecutionPolicy

Output:

Unrestricted

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 . . .


The system is Windows Server 2008 R2.

What am I doing wrong?


阅读 217

收藏
2023-12-27

共1个答案

小能豆

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.

Here are some steps to troubleshoot and resolve the issue:

  1. Check the Scope of the Execution Policy: Ensure that you are setting the execution policy at the correct scope. If you are running the PowerShell command with elevated privileges (Run as Administrator), it should apply to all users. However, if you’re setting it without elevation, it may only apply to the current user.

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine

  1. Check Group Policy: Group Policy settings can override local execution policies. Run the following command to see if a Group Policy is affecting the execution policy:

Get-ExecutionPolicy -List

If a Group Policy is present, you might need to contact your system administrator to adjust it.

  1. Check 32-bit vs 64-bit PowerShell: The warning “Running x86 PowerShell” indicates that you might be running a 32-bit version of PowerShell. Ensure that you are using the 64-bit version if your system is 64-bit. The 32-bit version has a separate execution policy.

$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

  1. Check Remote Signed Policy: If the script is on a remote location, the RemoteSigned execution policy might be applied. Try setting it specifically for scripts:

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.

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.

2023-12-27