0
0
PowershellHow-ToBeginner · 3 min read

How to Use Execution Policy in PowerShell: Simple Guide

Use the Set-ExecutionPolicy cmdlet in PowerShell to control script execution permissions. You can set policies like Restricted, RemoteSigned, or Unrestricted to allow or block scripts from running.
📐

Syntax

The basic syntax to set the execution policy is:

  • Set-ExecutionPolicy -ExecutionPolicy <PolicyName>: Sets the policy.
  • -Scope <ScopeName> (optional): Defines where the policy applies (e.g., CurrentUser, LocalMachine).
  • -Force (optional): Applies the change without asking for confirmation.
powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
💻

Example

This example sets the execution policy to RemoteSigned for the current user, allowing scripts created locally to run but requiring downloaded scripts to be signed.

powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
Get-ExecutionPolicy -Scope CurrentUser
Output
RemoteSigned
⚠️

Common Pitfalls

Common mistakes include:

  • Trying to set the policy without administrator rights when changing LocalMachine scope.
  • Not specifying the scope and unintentionally changing the policy for all users.
  • Ignoring the confirmation prompt without using -Force.
  • Expecting the policy to allow scripts without understanding the difference between policies like Restricted and RemoteSigned.
powershell
## Wrong: Changing LocalMachine without admin rights
Set-ExecutionPolicy -ExecutionPolicy Unrestricted

## Right: Change for current user without admin
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser -Force
📊

Quick Reference

Execution PolicyDescription
RestrictedNo scripts run. This is the default on Windows.
AllSignedOnly scripts signed by a trusted publisher run.
RemoteSignedLocally created scripts run; downloaded scripts must be signed.
UnrestrictedAll scripts run; warnings for downloaded scripts.
BypassNo restrictions or warnings.
UndefinedNo policy set in the scope.

Key Takeaways

Use Set-ExecutionPolicy to control script permissions in PowerShell.
Specify the scope to avoid changing policies for all users unintentionally.
Use -Force to skip confirmation prompts when setting policies.
RemoteSigned is a safe default allowing local scripts but protecting from unsigned downloads.
Administrator rights are required to change policies at the LocalMachine scope.