简体   繁体   中英

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

I have a power shell script that runs to stop services, 'stop / terminate process', delete 2 files and then restart.

I can run this script perfect on my Windows 10 64 Bit Host Machine - with ZERO issues. I try to run it in my Virtual Machines and I get the error

cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170

SO just for giggles I went to see my group policies and they are not configured on either machine.

Administrative Templates > Windows Components > Windows PowerShell Not Configured.

So why the issue on the virtual machine and not in my host?

EDIT Ran Get-ExecutionPolicy and also Get-ExecutionPolicy-List on VM Restricted

MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine       Undefined

Ran it on my Host

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine    Unrestricted

组策略屏幕截图

I do not know how my local machine was changed - software installation??

The following will allow all local scripts to execute on the VM, irrespective of whether they're signed or not:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

I am going to go out on a limb here and just rehash a portion of About Execution Policies .

The default execution policy for Windows client OSes is Restricted. This means that a script will not run automatically. If your VM has a Windows client OS and you have never changed the execution policy, then your issue is expected. If the one Windows 10 machine works without issues, then someone changed the execution policy.

On the problematic VMs, you will need to determine the scope (or account) that is running your script. Then you will need to set the execution policy accordingly.

If you are testing running a script while logged into the server as yourself, then you can just open a PowerShell console and run the following:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Then run the script in that same console.

The following command will list the execution policy for all scopes on that machine:

Get-ExecutionPolicy -List

You should compare the command above on the working system and the non-working system. Your issue likely be the execution policy setting for the particular scope that is running the script. If you read the link in my post, it should help you determine what you need to change specifically.

打开你的 PowerShell 并输入以下命令

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

If you are on Windows here is what you have to follow:

  1. Press the [windows] button and then type PowerShell .
  2. Run as Adiministrator
  3. Copy and Paste the following command and hit [Enter]
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
  1. Type Y and hit [Enter]
  2. Rerun the command and type A hit [Enter]
  3. Close the powershell and try again

Good luck .

I had the same problem with VS Code then I check the cmd with Administrator run. There is no problem so better to use CMD easy way to pass this problem绕过安全设置的屏幕截图

以管理员身份运行 Powershell 并运行以下命令: set-executionpolicy remotesigned

The least problematic approach is to use the command:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

This will get around Admin user authority issues.

Open your powershell as an administrator and then paste those commands:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

Then choose A

I had the same issue in my PC. Open the windows PowerShell ISE in administrator mode and run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine This command solved my issue.

After running powershell as administrator

run the following commands

1.Get-ExecutionPolicy -List 2.Set-ExecutionPolicy Unrestricted 3.Set-ExecutionPolicy Unrestricted -Force

(may be you need to restart the machine)

I had same issue when trying to create a vue application by running vue create my-project

To fix this I have followed below steps

  1. Open powershell as an administrator on Windows
  2. Run this command - Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
  3. Now open a new session on your terminal and run your application specific script. It worked.

user powerShell as admin and execute the following commends:

1-Set-ExecutionPolicy RemoteSigned

2-Get-ExecutionPolicy -List

3-Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine*

and rerun the scrips again and it will work

I m just farwarding all the changes that implies with setting the ExcecutionPolicy to RemoteSigned with the command : Set-ExecutionPolicy -ExecutionPolicy RemoteSigned ( I really recommend to first give a look at the other policies offered : Windows Execution Policies )

RemoteSigned :

  • The default execution policy for Windows server computers.
  • Scripts can run.
  • Requires a digital signature from a trusted publisher on scripts and configuration files that are downloaded from the internet which includes email and instant messaging programs.
  • Doesn't require digital signatures on scripts that are written on the local computer and not downloaded from the internet.
  • Runs scripts that are downloaded from the internet and not signed.
  • Risks running unsigned scripts from sources other than the internet and signed scripts that could be malicious.

Note that on Windows, browsers sign downloaded files and mark them as 'coming from the Internet'. If u want to unblock such a script, u can use the cmd Unblock-File .

user powerShell as admin and execute the following commends:

PS C:\WINDOWS\system32> Get-ExecutionPolicy -List

    Scope ExecutionPolicy
    ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process    Unrestricted
  CurrentUser    Unrestricted
 LocalMachine    Unrestricted

To unrestrict the execution policy:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser

Under your normal user. The following requires to open an administrator instance:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine

as an administrator.

You might need to restart the computer afterwards.

You will see peerjs server is working

Use the syntax below

Set-ExecutionPolicy -Scope CurrentUser

Enter the "Unrestricted" as your value in the ExecutionPolicy parameter syntax below:

ExecutionPolicy:Unrestricted

Then run your command; you can check the node version or any version of the software you installed after implementing the commands above

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM