Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

PS C:\Users\Administrator\> Get-ExecutionPolicy Unrestricted 

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

What am I doing wrong?

like image 778
Conor Avatar asked Oct 27 '10 21:10

Conor


People also ask

How do I enable script execution in PowerShell?

Select Start > All Programs > Windows PowerShell version > Windows PowerShell. Type Set-ExecutionPolicy RemoteSigned to set the policy to RemoteSigned. Type Set-ExecutionPolicy Unrestricted to set the policy to Unrestricted. Type Get-ExecutionPolicy to verify the current settings for the execution policy.

What do it mean running scripts are disabled in this system?

The thing is that Windows has an “Execution Policy” that the script needs to bypass in order for it to be executed. If the Execution Policy is set to “Restricted” then no script can be run on the computer.


2 Answers

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 
like image 56
Chad Miller Avatar answered Oct 10 '22 20:10

Chad Miller


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

powershell -ExecutionPolicy Bypass -File script.ps1 
like image 44
Jack Edmonds Avatar answered Oct 10 '22 21:10

Jack Edmonds