PowerShell execution policy: check, change and run scripts
Check and change the PowerShell execution policy per scope, unblock downloaded scripts and run scripts from a network share.
PowerShell's execution policy decides which scripts can run on a machine or for a user. This article shows how to check the policy for each scope, change it, unblock a downloaded script and run one script without changing the policy.
Check the current policy
Get-ExecutionPolicy -List
The policy is evaluated by scope, from the highest precedence (MachinePolicy) to the lowest (Process). MachinePolicy and UserPolicy are normally set by Group Policy.
Change the policy
| Scope | Applies to | Example |
|---|---|---|
| Process | The current session only | Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass |
| CurrentUser | The current user | Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force |
| LocalMachine | All users (administrator rights required) | Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Bypass -Force |
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force
Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Bypass -Force
Unblock a downloaded script
A script downloaded from the internet carries a "Mark of the Web" and can be blocked even when the policy allows it. Remove the mark with:
Unblock-File -Path C:\Downloads\script1.ps1
Run one script without changing the policy
powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\script.ps1
Set the policy with Group Policy
- Run
gpedit.mscto open the Group Policy Editor. - In the left tree, go to Local Computer Policy, Computer Configuration, Administrative Templates, Windows Components, Windows PowerShell.
- In the right pane, double-click Turn On Script Execution.
- In the dialog, choose Enabled, then select the policy to apply (for example, Allow all scripts).
The equivalent registry values are shown below. Import them only if Group Policy is not an option.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\PowerShell]
"EnableScripts"=dword:00000001
"ExecutionPolicy"="Bypass"
Scripts on a network share
Running a script from a UNC share can show a "Security warning" prompt asking whether to run it. Options:
Set-ExecutionPolicy Unrestricted -Scope CurrentUser
or run the script with the policy set for that process only:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\script.ps1
Notes
BypassandUnrestricteddisable the protection against untrusted scripts. Use them only for scripts you trust.- Reference: Set-ExecutionPolicy (Microsoft Learn)