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

PowershellWindows Server-2008-R2

Powershell Problem Overview


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?

Powershell Solutions


Solution 1 - Powershell

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

Solution 2 - Powershell

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

powershell -ExecutionPolicy Bypass -File script.ps1

Solution 3 - Powershell

I had a similar issue and noted that the default cmd on Windows Server 2012, was running the x64 one.

For Windows 11, Windows 10, Windows 7, Windows 8, Windows Server 2008 R2 or Windows Server 2012, run the following commands as Administrator:

x86 (32 bit)
Open C:\Windows\SysWOW64\cmd.exe
Run the command powershell Set-ExecutionPolicy RemoteSigned

x64 (64 bit)
Open C:\Windows\system32\cmd.exe
Run the command powershell Set-ExecutionPolicy RemoteSigned

You can check mode using

  • In CMD: echo %PROCESSOR_ARCHITECTURE%
  • In Powershell: [Environment]::Is64BitProcess

References:
MSDN - Windows PowerShell execution policies
Windows - 32bit vs 64bit directory explanation

Solution 4 - Powershell

Most of the existing answers explain the How, but very few explain the Why. And before you go around executing code from strangers on the Internet, especially code that disables security measures, you should understand exactly what you're doing. So here's a little more detail on this problem.

From the TechNet About Execution Policies Page:

> Windows PowerShell execution policies let you determine the conditions under which Windows PowerShell loads configuration files and runs scripts.

The benefits of which, as enumerated by PowerShell Basics - Execution Policy and Code Signing, are:

>* Control of Execution - Control the level of trust for executing scripts. >* Command Highjack - Prevent injection of commands in my path. >* Identity - Is the script created and signed by a developer I trust and/or a signed with a certificate from a Certificate Authority I trust. >* Integrity - Scripts cannot be modified by malware or malicious user.

To check your current execution policy, you can run Get-ExecutionPolicy. But you're probably here because you want to change it.

To do so you'll run the Set-ExecutionPolicy cmdlet.

You'll have two major decisions to make when updating the execution policy.

Execution Policy Type:
  • Restricted - No Script either local, remote or downloaded can be executed on the system.
  • AllSigned - All script that are ran require to be digitally signed.
  • RemoteSigned - All remote scripts (UNC) or downloaded need to be signed.
  • Unrestricted - No signature for any type of script is required.
Scope of new Change
  • LocalMachine - The execution policy affects all users of the computer.
  • CurrentUser - The execution policy affects only the current user.
  • Process - The execution policy affects only the current Windows PowerShell process.

† = Default

For example: if you wanted to change the policy to RemoteSigned for just the CurrentUser, you'd run the following command:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Note: In order to change the Execution policy, you must be running PowerShell As Adminstrator. If you are in regular mode and try to change the execution policy, you'll get the following 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.

If you want to tighten up the internal restrictions on your own scripts that have not been downloaded from the Internet (or at least don't contain the UNC metadata), you can force the policy to only run signed sripts. To sign your own scripts, you can follow the instructions on Scott Hanselman's article on Signing PowerShell Scripts.

Note: Most people are likely to get this error whenever they open Powershell because the first thing PS tries to do when it launches is execute your user profile script that sets up your environment however you like it.

The file is typically located in:

%UserProfile%\My Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1

You can find the exact location by running the powershell variable

$profile

If there's nothing that you care about in the profile, and don't want to fuss with your security settings, you can just delete it and powershell won't find anything that it cannot execute.

Solution 5 - Powershell

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 Unrestricted or Bypass.

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

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -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.

Solution 6 - Powershell

Also running this command before the script also solves the issue:

Set-ExecutionPolicy Unrestricted

Solution 7 - Powershell

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!

Solution 8 - Powershell

If you are in an environment where you are not an administrator, you can set the Execution Policy just for you, and it will not require administrator.

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

or

Set-ExecutionPolicy -Scope "CurrentUser" -ExecutionPolicy "Unrestricted"

You can read all about it in the help entry.

Help Get-ExecutionPolicy -Full
Help Set-ExecutionPolicy -Full

Solution 9 - Powershell

RemoteSigned: all scripts you created yourself will be run, and all scripts downloaded from the Internet will need to be signed by a trusted publisher.

OK, change the policy by simply typing:

Set-ExecutionPolicy RemoteSigned

Solution 10 - Powershell

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 ;)

Solution 11 - Powershell

  1. Open powershell as administration
Set-ExecutionPolicy -Scope "CurrentUser" -ExecutionPolicy "RemoteSigned"

use this command

Solution 12 - Powershell

sou should run this command

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

Solution 13 - Powershell

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"

Solution 14 - Powershell

Open Windows PowerShell Command and run below query to change ExecutionPolicy

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

if it ask for confirm changes press 'Y' and hit enter.

Solution 15 - Powershell

Open command prompt in windows, If the problem is only with powershell use the following command,

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

Solution 16 - Powershell

you may try this and select "All" Option

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

Solution 17 - Powershell

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

Now run the run command what ever you are using.. Trust this the app will runs.. Enjoy :)

Solution 18 - Powershell

Setting the execution policy is environment-specific. If you are trying to execute a script from the running x86 ISE you have to use the x86 PowerShell to set the execution policy. Likewise, if you are running the 64-bit ISE you have to set the policy with the 64-bit PowerShell.

Solution 19 - Powershell

You can also bypass this by using the following command:

PS > powershell Get-Content .\test.ps1 | Invoke-Expression

You can also read this article by Scott Sutherland that explains 15 different ways to bypass the PowerShell Set-ExecutionPolicy if you don't have administrator privileges:

15 Ways to Bypass the PowerShell Execution Policy

Solution 20 - Powershell

I have also faced similar issue try this hope it helps someone As I'm using windows so followed the steps as given below Open command prompt as an administrator and then go to this path

C:\Users\%username%\AppData\Roaming\npm\

Look for the file ng.ps1 in this folder (dir) and then delete it (del ng.ps1)

You can also clear npm cache after this though it should work without this step as well. Hope it helps as it worked for me.

Hope it helps

Solution 21 - Powershell

In the PowerShell ISE editor I found running the following line first allowed scripts.

Set-ExecutionPolicy RemoteSigned -Scope Process

Solution 22 - Powershell

Set-ExecutionPolicy RemoteSigned

Executing this command in administrator mode in powershell will solve the problem.

Solution 23 - Powershell

In Window 10:

if you are not administrator, you can use this

powershell Set-ExecutionPolicy -Scope CurrentUser

cmdlet Set-ExecutionPolicy at command pipeline position 1 Supply values for the following parameters: ExecutionPolicy: RemoteSigned

it solved my problem like a charm!

Solution 24 - Powershell

For Windows 11..... It is indeed very easy. Just open settings app Navigate to Privacy and SecurityPrivacy and security image

Click on For Developers and scroll to bottom and find PowerShell option under which check the checkbox stating "Change the execution policy ...... remote scripts".Developer options image

Solution 25 - Powershell

First, you have to need to open the powershell and run this command.

set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Then it will ask yo to confirm. Type Y and press Enter

When you run this command, you can see that your system has set all policies for the current user as remotely. It will take few seconds to complete this process. The image will be shown like below.

enter image description here

To check if execution policy has set, Type : Get-ExecutionPolicy

If its set output would be like this :

enter image description here

Solution 26 - Powershell

  1. Open PowerShell as Administrator and run Set-ExecutionPolicy -Scope CurrentUser
  2. Provide RemoteSigned and press Enter
  3. Run Set-ExecutionPolicy -Scope CurrentUser
  4. Provide Unrestricted and press Enter

Solution 27 - Powershell

I get another warning when I tryit to run Set-ExecutionPolicy RemoteSigned

I solved with this commands

Set-ExecutionPolicy "RemoteSigned" -Scope Process -Confirm:$false

Set-ExecutionPolicy "RemoteSigned" -Scope CurrentUser -Confirm:$false

Solution 28 - Powershell

In windows 10, enable the option under the name: 'Install apps from any source, including loose files.' enter image description here

it fixed the issue for me

Solution 29 - Powershell

Open PowerShell as a administrator. Run the following command

Set-ExecutionPolicy RemoteSigned

Type Y when asked!

Solution 30 - Powershell

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

Solution 31 - Powershell

In PowerShell 2.0, the execution policy was set to disabled by default.

From then on, the PowerShell team has made a lot of improvements, and they are confident that users will not break things much while running scripts. So from PowerShell 4.0 onward, it is enabled by default.

In your case, type Set-ExecutionPolicy RemoteSigned from the PowerShell console and say yes.

Solution 32 - Powershell

Go to the registry path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell and set ExecutionPolicy to RemoteSigned.

Solution 33 - Powershell

I had the same problem today. 64-bit execution policy was unrestricted, while 32-bit was restricted.

Here's how to change just the 32-bit policy remotely:

Invoke-Command -ComputerName $servername -ConfigurationName Microsoft.PowerShell32 -scriptblock {Set-ExecutionPolicy unrestricted}

Solution 34 - Powershell

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

Set-ExecutionPolicy -ExecutionPolicy Remotesigned 

Solution 35 - Powershell

If you're here because of running it with Ruby or Chef and using `` system execution, execute as follows:

`powershell.exe -ExecutionPolicy Unrestricted -command [Environment]::GetFolderPath(\'mydocuments\')`

That command is for getting "MyDocuments" Folder.

-ExecutionPolicy Unrestricted does the trick.

I hope it's helpful for someone else.

Solution 36 - Powershell

Several answers point to execution policy. However some things require "runas administrator" also. This is safest in that there is no permanent change to execution policy, and can get past administrator restriction. Use with schedtask to start a batch with:

    runas.exe /savecred /user:administrator powershell -ExecutionPolicy ByPass -File script.ps1

from both Jack Edmonds above, and Peter Mortensen / Dhana of post https://stackoverflow.com/questions/8249705/how-to-run-an-application-as-run-as-administrator-from-the-command-prompt

Solution 37 - Powershell

You can use a special way to bypass it:

Get-Content "PS1scriptfullpath.ps1" | Powershell -NoProfile -

It pipes the content of powershell script to powershell.exe and executes it bypassing the execution policy.

Solution 38 - Powershell

delete the ng.ps1 file in C:\Users[your user]\AppData\Roaming\npm

and delete npm cache file in C:\Users\USER\AppData\Roaming

Solution 39 - Powershell

if you have git installed, just use git bash.

enter image description here

Solution 40 - Powershell

There's great information in the existing answers, but let me attempt a systematic overview:

Context

PowerShell's effective execution policy applies:

  • to script files (.ps1) only, not also to calls to cmdlets (e.g., Get-ChildItem), for instance.
  • on Windows only (that is, on Unix-like platforms (Linux, macOS) execution policies do not apply)

On workstation editions of Windows, script-file execution is disabled by default (policy Restricted), requiring either a persistent modification of the policy to enable it, or a current-process-only modification such as via the -ExecutionPolicy parameter when calling the PowerShell CLI, powershell.exe (Windows PowerShell edition) / pwsh.exe (PowerShell (Core) edition).

Execution policies are maintained separately:

  • for the two PowerShell editions:

    • the legacy, Windows-only, ships-with-Windows Windows PowerShell edition (whose latest and last version is v5.1.x)
    • the modern, cross-platform, install-on-demand PowerShell (Core) edition (v6+).
  • for the 32-bit and 64-bit versions of Windows PowerShell (both of which are preinstalled)

    • Note: If you were to install 32-bit and 64-bit versions of PowerShell (Core) side by side (which would be unusual), only the LocalMachine scope would be bitness-specific.

For a given edition / bitness combination of PowerShell, the execution policies can be set in multiple scopes, but there's only ever one effective policy, based on precedence rules - see below.

Details
  • In PowerShell on Windows, script-file execution is disabled by default in workstation editions of Windows (on Unix, execution policies do not apply); that is, the default execution policy in workstation editions of Windows is Restricted, whereas in server editions, it is RemoteSigned; see the conceptual about_Execution_Policies help topic for a description of all available policies.

  • To set a (local) policy that permits script execution, use Set-ExecutionPolicy. There are three scopes that Set-ExecutionPolicy can target, using the -Scope parameter (see below); changing the LocalMachine scope requires elevation (running as admin).

    • To unset a previously set policy in a given scope, use Undefined
  • A frequently used policy that provides a balance between security and convenience is RemoteSigned, which allows local scripts - including from network shares - to execute without containing a signature, while requiring scripts downloaded from the internet to be signed (assuming that the downloading mechanism marks such as scripts as internet-originated, which web browsers do by default). For instance, to set the current user's execution policy to RemoteSigned, run the following:

    Set-ExecutionPolicy -Scope CurrentUser RemoteSigned -Force
    
  • The PowerShell CLI (powershell.exe for Windows PowerShell, pwsh.exe for PowerShell (Core), v6+) accepts a process-specific -ExecutionPolicy <policy> argument too, which is often used for ad-hoc policy overrides (only for the process being created, the equivalent of Set-ExecutionPolicy -Scope Process ..); e.g.:

    pwsh.exe -ExecutionPolicy RemoteSigned -File someScript.ps1
    
  • Important:

    • Execution policies can also be set via Group Policy Objects (GPOs), in which case they can not be changed or overridden with Set-ExecutionPolicy or via the CLI.

    • Execution policies can be set in various scopes, and which one is in effect is determined by their precedence (run Get-ExecutionPolicy -List to see all scopes and their respective policies), in descending order:

      • MachinePolicy (via GPO; cannot be overridden locally)
      • UserPolicy (via GPO; cannot be overridden locally)
      • Process (current process only; typically set ad-hoc via the CLI)
      • CurrentUser (as set by Set-ExecutionPolicy)
      • LocalMachine (as set by Set-ExecutionPolicy, with admin rights)

Solution 41 - Powershell

Open cmd instead of powershell. This helped for me...

Solution 42 - Powershell

Run Set-ExecutionPolicy RemoteSigned command

Solution 43 - Powershell

Happened to me as well. For me, the solution was simple. I didn't realize that the path in the command prompt to run Nodemon was different to where I installed the package.

So it gave me the same error that you've mentioned.

Changing my path resolved it.

Solution 44 - Powershell

Open the PowerShell window as an Administrator. It will work.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionConorView Question on Stackoverflow
Solution 1 - PowershellChad MillerView Answer on Stackoverflow
Solution 2 - PowershellJack EdmondsView Answer on Stackoverflow
Solution 3 - PowershellRalph WillgossView Answer on Stackoverflow
Solution 4 - PowershellKyleMitView Answer on Stackoverflow
Solution 5 - PowershellPratik PatilView Answer on Stackoverflow
Solution 6 - Powershellmanik sikkaView Answer on Stackoverflow
Solution 7 - PowershellRyanView Answer on Stackoverflow
Solution 8 - PowershellMicah 'Powershell Ninja'View Answer on Stackoverflow
Solution 9 - PowershellJaimeView Answer on Stackoverflow
Solution 10 - PowershellhugocabralView Answer on Stackoverflow
Solution 11 - PowershellMD SHAYONView Answer on Stackoverflow
Solution 12 - PowershellOmidDarvishiView Answer on Stackoverflow
Solution 13 - PowershellQamarView Answer on Stackoverflow
Solution 14 - PowershellR15View Answer on Stackoverflow
Solution 15 - PowershellphpnerdView Answer on Stackoverflow
Solution 16 - PowershellTaqi Raza KhanView Answer on Stackoverflow
Solution 17 - PowershellT ManojithView Answer on Stackoverflow
Solution 18 - PowershellScriptAholicView Answer on Stackoverflow
Solution 19 - PowershellAlexander SinnoView Answer on Stackoverflow
Solution 20 - PowershellRashi GoyalView Answer on Stackoverflow
Solution 21 - PowershellDavid DouglasView Answer on Stackoverflow
Solution 22 - PowershellUserView Answer on Stackoverflow
Solution 23 - PowershellJeffrey CheongView Answer on Stackoverflow
Solution 24 - PowershellSoumil TewariView Answer on Stackoverflow
Solution 25 - Powershellghost21bladeView Answer on Stackoverflow
Solution 26 - PowershellRamanujam AllamView Answer on Stackoverflow
Solution 27 - PowershellGeorge C.View Answer on Stackoverflow
Solution 28 - PowershellEliasView Answer on Stackoverflow
Solution 29 - PowershellYasirView Answer on Stackoverflow
Solution 30 - PowershellWIlliamTView Answer on Stackoverflow
Solution 31 - PowershellAdil ArifView Answer on Stackoverflow
Solution 32 - Powershellsunish surendran.kView Answer on Stackoverflow
Solution 33 - Powershellrko281View Answer on Stackoverflow
Solution 34 - PowershelllokeshbandharapuView Answer on Stackoverflow
Solution 35 - PowershellJGutierrezCView Answer on Stackoverflow
Solution 36 - PowershellKirt CarsonView Answer on Stackoverflow
Solution 37 - PowershellWasifView Answer on Stackoverflow
Solution 38 - PowershellMohammad Atif AftabView Answer on Stackoverflow
Solution 39 - Powershellel_yonousiView Answer on Stackoverflow
Solution 40 - Powershellmklement0View Answer on Stackoverflow
Solution 41 - PowershellJelmer JellemaView Answer on Stackoverflow
Solution 42 - PowershellmaxxiView Answer on Stackoverflow
Solution 43 - Powershellsaadi123View Answer on Stackoverflow
Solution 44 - PowershellSuganthan RajView Answer on Stackoverflow