π Step 1: Open PowerShell as Administrator (Admin Mode)
You can access PowerShell by either searching for it or using Win + X and selecting Terminal (Admin).
Press Windows + S (or click the search bar).
Type PowerShell.
Right-click Windows PowerShell β select Run as Administrator.
If you see a UAC prompt, click Yes.
π§ Step 2: Check your current Execution Policy
The execution policy is a safety feature in PowerShell. It controls whether scripts are allowed to run. This command shows what your system is currently set to.
Get-ExecutionPolicy
π§© Step 3: Change Execution Policy (Enable or Disable Scripts)
Use these commands to control whether scripts can run. For most users, RemoteSigned is the best balance. The -Scope CurrentUser option changes it for your user account only (safer and usually does not require full system changes).
β Recommended: Allow scripts (Current User)
This allows scripts you created locally to run, but downloaded scripts must be signed.
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
π Disable all scripts (Most restrictive)
Use this if you want to block scripts completely.
Set-ExecutionPolicy Restricted -Scope CurrentUser
πΎ Step 4: Save a PowerShell (.ps1) Script
A .ps1 file is a PowerShell script file that contains a series of commands. To create and save a script:
β Save the script as a .ps1 file:
- Open Notepad or any text editor.
- Write your PowerShell commands in the editor.
- Click File β Save As.
- Choose a location to save the file, and type script.ps1 in the File name field.
- Ensure the Save as type is set to All Files.
- Click Save.
Example .ps1 script:
# Example PowerShell Script to Enable RemoteSigned Policy
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
β How to run the .ps1 script:
1. Navigate to the folder where your .ps1 file is saved in PowerShell:
cd "C:\path\to\your\script\
2. Run the script:
.\script.ps1
π§― Step 5: Set Execution Policy for All Users (System-wide)
This affects the whole computer. It usually requires admin privileges. Only do this if you manage the machine and understand the impact.
Set-ExecutionPolicy RemoteSigned -Scope LocalMachine
β©οΈ Revert to default (Restricted)
Set-ExecutionPolicy Restricted -Scope LocalMachine
π§© Optional: Use a PowerShell Profile (Advanced)
A PowerShell profile is a script that runs automatically every time PowerShell opens. You can use it to set your preferred policy each time.
π Open your profile file
notepad.exe $PROFILE
β Add this line to set RemoteSigned on startup
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
π§Ύ Quick Summary (Copy-friendly)
Search βPowerShellβ β Right-click β Run as Administrator.
Get-ExecutionPolicy
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Set-ExecutionPolicy Restricted -Scope CurrentUser