PowerShell says “execution of scripts is disabled on this system.”

前端 未结 30 2364
傲寒
傲寒 2020-11-22 00:45

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

Management_Instal

相关标签:
30条回答
  • 2020-11-22 01:15

    Open the Powershell console as an administrator, and then set the execution policy

    Set-ExecutionPolicy -ExecutionPolicy Remotesigned 
    
    0 讨论(0)
  • 2020-11-22 01:17

    I'm using Windows 10 and was unable to run any command. The only command that gave me some clues was this:

    [x64]

    1. Open C:\Windows\SysWOW64\cmd.exe [as administrator]
    2. Run the command> powershell Set-ExecutionPolicy Unrestricted

    But this didn't work. It was limited. Probably new security policies for Windows10. I had this error:

    Set-ExecutionPolicy: Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined at a more specific scope. Due to the override, your shell will retain its current effective execution policy of...

    So I found another way (solution):

    1. Open Run Command/Console (Win + R)
    2. Type: gpedit.msc (Group Policy Editor)
    3. Browse to Local Computer Policy -> Computer Configuration -> Administrative Templates -> Windows Components -> Windows Powershell.
    4. Enable "Turn on Script Execution"
    5. Set the policy as needed. I set mine to "Allow all scripts".

    Now open PowerShell and enjoy ;)

    0 讨论(0)
  • 2020-11-22 01:17

    Win + R and type copy paste command and press OK:

    powershell Set-ExecutionPolicy -Scope "CurrentUser" -ExecutionPolicy "RemoteSigned"
    

    And execute your script.

    Then revert changes like:

    powershell Set-ExecutionPolicy -Scope "CurrentUser" -ExecutionPolicy "AllSigned"
    
    0 讨论(0)
  • 2020-11-22 01:17

    I found this line worked best for one of my Windows Server 2008 R2 servers. A couple of others had no issues without this line in my PowerShell scripts:

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force -Scope Process
    
    0 讨论(0)
  • 2020-11-22 01:18

    We can get the status of current ExecutionPolicy by the command below:

    Get-ExecutionPolicy;
    

    By default it is Restricted. To allow the execution of PowerShell scripts we need to set this ExecutionPolicy either as Bypass or Unrestricted.

    We can set the policy for Current User as Bypass or Unrestricted by using any of the below PowerShell commands:

    Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force;
    
    Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force;
    

    Unrestricted policy loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs.

    Whereas in Bypass policy, nothing is blocked and there are no warnings or prompts during script execution. Bypass ExecutionPolicy is more relaxed than Unrestricted.

    0 讨论(0)
  • 2020-11-22 01:22

    In Windows 7:

    Go to Start Menu and search for "Windows PowerShell ISE".

    Right click the x86 version and choose "Run as administrator".

    In the top part, paste Set-ExecutionPolicy RemoteSigned; run the script. Choose "Yes".

    Repeat these steps for the 64-bit version of Powershell ISE too (the non x86 version).

    I'm just clarifying the steps that @Chad Miller hinted at. Thanks Chad!

    0 讨论(0)
提交回复
热议问题