To get or set the execution policy in PowerShell or CMD, use the Get-ExecutionPolicy
and Set-ExecutionPolicy
cmdlets. Hereβs how to use them:
In PowerShell, run:
Get-ExecutionPolicy
You may get Restricted
in the response.
If you just want to run a script without changing the system policy, use:
powershell.exe -ExecutionPolicy Bypass -File "C:\Path\To\Script.ps1"
Requires Administrator privileges:
To set to RemoteSigned
, Bypass
, or AllSigned
globally:
Set-ExecutionPolicy RemoteSigned -Scope LocalMachine
Other scopes include:
Process
β Temporary, lasts for current PowerShell session.CurrentUser
β Applies to the current user.LocalMachine
β Applies to all users on the computer (admin required).Example:
Set-ExecutionPolicy Bypass -Scope Process
From Command Prompt (CMD), to get the policy:
powershell -Command "Get-ExecutionPolicy"
To run a script with bypass:
powershell -ExecutionPolicy Bypass -File "C:\Path\To\Script.ps1"
Using Bypass
disables all execution policy protections β only use it when necessary, and never leave it set system-wide unless you understand the risks.
Would you like help writing a script that sets and restores the policy safely?