Run PowerShell Script as Admin Without Restrictions
Running PowerShell scripts in Windows 11 often results in execution policy errors, especially when administrative privileges are required. This guide explains how to execute PowerShell scripts with full administrator privileges while bypassing execution policy restrictions using one-liner commands, elevated sessions, desktop shortcuts, and self-elevating script wrappers.
Method 1:
Use the Bypass Parameter via Command Line
The most direct way to run a script without altering system-wide
security settings is to use the -ExecutionPolicy Bypass
argument from an elevated command-line interface.
- Press Win + S, type
powershell, right-click Windows PowerShell (or Terminal), and select Run as administrator. - Run the following command, replacing the path with the actual location of your script:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\Path\To\YourScript.ps1"-NoProfile: Prevents loading the default user profile, speeding up execution.-ExecutionPolicy Bypass: Allows the script to run without blocking or showing warning prompts for this single process only.
Method 2: Bypass Policy Inside an Elevated Session
If you already have an elevated PowerShell session open, you can set the bypass scope strictly to the current process. This ensures system-level security policies remain intact after you close the window.
- Open PowerShell or Windows Terminal as Administrator.
- Set the policy for the current session:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force- Execute your script:
& "C:\Path\To\YourScript.ps1"Method 3: Create a “Run as Administrator” Shortcut
You can create a desktop shortcut that automatically requests administrator rights and bypasses the policy upon launching.
- Right-click on your Desktop and choose New > Shortcut.
- In the target field, enter:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\Path\To\YourScript.ps1"
- Name the shortcut and click Finish.
- Right-click the newly created shortcut and select Properties.
- Go to the Shortcut tab, click Advanced…, check the Run as administrator box, and click OK.
Method 4: Add a Self-Elevating Header to the Script
To make the .ps1 file automatically elevate itself and
bypass policies without manual intervention, place this block at the
very top of your script:
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Start-Process powershell.exe -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
exit
}
# Your actual script code starts below:
Write-Host "Running with Administrator privileges and Bypassed policy!" -ForegroundColor GreenWhen executed, this script detects whether it has administrative
privileges. If not, it launches a new elevated PowerShell process with
the -ExecutionPolicy Bypass flag and closes the
unprivileged instance.