Reputation: 2808
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 ??
Upvotes: 98
Views: 316094
Reputation: 343
Windows settings worked for me:
Go to Settings > System > For developers
:
Go to Powershell
and enable the Change execution policy ...
option:
Upvotes: 2
Reputation: 9321
Windows
here is what you have to follow:[windows]
button and then type PowerShell
.Administrator
[Enter]
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
Y
and hit [Enter]
A
hit [Enter]
Good luck.
Upvotes: 78
Reputation: 25001
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 is 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.
Upvotes: 153
Reputation: 1775
I have tried these two ways that you can tackle this problem succesfully:
By enabling PowerShell execution policies:
PS C:\Users\usr1>Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
For example, I encountered this problem when i wanted to run yarn command at my project's root folder. Then by running the command above, I was abled to run the comand yarn without a problem.
Upvotes: 1
Reputation: 445
After running powershell as administrator, run the following commands:
May be you need to restart the machine.
Upvotes: 2
Reputation: 11
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
Upvotes: 0
Reputation: 1403
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
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
Upvotes: 1
Reputation: 21
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
Upvotes: 0
Reputation: 582
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 :
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
.
Upvotes: 0
Reputation: 1
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
Upvotes: 0
Reputation: 1101
The least problematic approach is to use the command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
This will get around Admin user authority issues.
Upvotes: 7
Reputation: 3866
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.
Upvotes: 1
Reputation: 91
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
Upvotes: 9
Reputation: 11
Open your powershell as an administrator and then paste those commands:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
Then choose A
Upvotes: 1
Reputation: 299
Open your PowerShell and enter the following command
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
Upvotes: 29
Reputation: 1301
Run Powershell as an administrator and run the following command:
set-executionpolicy remotesigned
Upvotes: 6