How to Set Execution Policy in PowerShell: Simple Steps
Use the
Set-ExecutionPolicy cmdlet in PowerShell to change the script execution policy. For example, run Set-ExecutionPolicy RemoteSigned in an elevated PowerShell window to allow local scripts and signed remote scripts to run.Syntax
The Set-ExecutionPolicy cmdlet changes the user or system policy that controls script execution in PowerShell.
-ExecutionPolicy: Specifies the policy level (e.g.,Restricted,RemoteSigned,Unrestricted).-Scope: Defines where the policy applies (Process,CurrentUser,LocalMachine).-Force: Skips confirmation prompts.
powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Example
This example sets the execution policy to RemoteSigned for the current user, allowing local scripts and signed remote scripts to run without prompts.
powershell
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force Get-ExecutionPolicy -Scope CurrentUser
Output
RemoteSigned
Common Pitfalls
Common mistakes include:
- Not running PowerShell as administrator when changing
LocalMachinescope, causing permission errors. - Forgetting to specify
-Scope, which changes the policy for all users and may require admin rights. - Ignoring confirmation prompts without using
-Force, which can halt the script.
powershell
## Wrong: Changing LocalMachine scope without admin rights Set-ExecutionPolicy RemoteSigned -Scope LocalMachine ## Right: Run PowerShell as admin or use CurrentUser scope Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
Quick Reference
| Execution Policy | Description |
|---|---|
| Restricted | No scripts can run (default on Windows). |
| RemoteSigned | Local scripts run; remote scripts must be signed. |
| Unrestricted | All scripts can run; warns on unsigned remote scripts. |
| Bypass | No restrictions or warnings. |
| AllSigned | All scripts must be signed by a trusted publisher. |
Key Takeaways
Use Set-ExecutionPolicy with the right scope to control script permissions safely.
Run PowerShell as administrator when changing system-wide policies (LocalMachine scope).
Use -Force to avoid confirmation prompts during scripting.
RemoteSigned is a good balance for running local scripts and signed remote scripts.
Check current policy with Get-ExecutionPolicy before changing it.