How to Run a PowerShell Script as Administrator

Your script restarts a service or edits a protected folder, and it stops with “Access is denied.” You’re signed in as an admin, yet the script still doesn’t have admin rights.

Quick answer: to run a PowerShell script as administrator, open PowerShell with Run as administrator and run the script there, or start an elevated copy of PowerShell with Start-Process -Verb RunAs:

Start-Process pwsh.exe -Verb RunAs -ArgumentList '-NoProfile -File "C:\Scripts\Repair-Spooler.ps1"'

In this tutorial, we’ll show every reliable way to run powershell script as administrator: an elevated console, an admin check, #Requires, a script that relaunches itself, batch files, shortcuts, Task Scheduler and sudo. We also explain why UAC won’t let a script skip the prompt.

What You Need Before You Start

You need Windows 10 or 11, PowerShell 7 or Windows PowerShell 5.1, and an account in the local Administrators group (or an admin’s credentials). Not sure about your account? You can list the local administrators with PowerShell first.

We ran every test in a normal window. Commands that would open a UAC prompt are shown as code only.

Step 1: Open PowerShell as Administrator

The simplest method is to start the whole console elevated, then run your script in it. On Windows 11, press Win+X and choose Terminal (Admin).

You can also click Start, type PowerShell (or pwsh), and choose Run as administrator. Or select it in Start search and press Ctrl+Shift+Enter instead of Enter.

Approve the UAC prompt, and the title bar starts with “Administrator:”. Now go to the script folder and run it with .\ in front. The guide to running scripts with parameters covers paths and arguments.

Step 2: Check if a Script Is Running as Administrator

Inside a script, ask Windows whether the current identity holds the Administrators role. We also read the token groups with whoami to see why the answer was False on an admin account:

$identity  = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = [Security.Principal.WindowsPrincipal]$identity
$isAdmin   = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
"Running as administrator: $isAdmin"

$groups = whoami /groups /fo csv | ConvertFrom-Csv
$admins = $groups | Where-Object SID -eq 'S-1-5-32-544'
$label  = $groups | Where-Object 'Group Name' -like 'Mandatory Label*'
"Administrators group: $($admins.Attributes)"
"Integrity level:      $($label.'Group Name')"

Output:

Running as administrator: False
Administrators group: Group used for deny only
Integrity level:      Mandatory Label\Medium Mandatory Level