There are several ways to run PowerShell scripts as an administrator, both interactively and non-interactively โ which is suitable for automation.
Keep in mind that a PowerShell script can run with administrator privileges either from an elevated PowerShell host or by elevating the specific command with Windows sudo.
Running PowerShell as Administrator (Interactive)
An elevated PowerShell session is required to run PowerShell scripts as an administrator. Opening the elevated PowerShell console triggers the UAC prompt.
- Right-click the Start button or press Win+X on the keyboard to open the Power User Menu on Windows.
- Click Windows PowerShell (Admin) (replaced with Terminal (Admin) on Windows 11) to open the elevated PowerShell console;

- Confirm the elevation at the UAC prompt.

- Any command or PowerShell script that is run from this console will be run as an administrator.
- For example, to run a specific PS1 script file, change the directory and run:
cd C:\PS
.\my_script.ps1

Run a PowerShell Script as Administrator with sudo
On Windows 11 version 24H2 and later, you can use the built-in sudo command to run a specific command or PowerShell script with elevated privileges from an unelevated console session. For example, to run a PowerShell script as admin, run the following command:
sudo .\my_script.ps1
You can also explicitly launch PowerShell 7 with elevated privileges:
sudo pwsh -File C:\PS\my_script.ps1
When you run a command with sudo, Windows displays the UAC elevation prompt according to the configured sudo settings. Unlike Run as administrator for Windows Terminal, sudo elevates only the specified command. The current PowerShell session remains non-elevated.
Here is an example:
whoami
sudo whoami
The first command runs with the privileges of the current user, while the second command runs with elevated privileges.ย If sudo is not enabled on the system, you can config it in Settings โ System โ For developers โ Enable sudo, or enable it using the appropriate Windows config mechanism.
Open an Elevated PowerShell Session in Windows Terminal
Windows Terminal can host both Windows PowerShell 5.1 and PowerShell 7 profiles. To open an elevated Terminal window, right-click Windows Terminal and select Run as administrator.
The following command opens a new PowerShell tab in Windows Terminal:
wt.exe -w 0 new-tab pwsh
In case Windows Terminal is started with admin privileges, all PowerShell sessions opened inside it will run elevated.
Note. Windows Terminal is a terminal host only. Whether you run Windows PowerShell 5.1 (powershell.exe) or PowerShell 7 (pwsh.exe) depends on the profile you select.
Run a PowerShell Script from File Explorer
Many users expect to see a Run as administrator option when right-clicking a .ps1 file. However, Windows does not provide a built-in way to directly run PowerShell script files elevated from File Explorer.
To run a script with admin privileges from File Explorer, follow the steps below:
- Search for PowerShell or Windows Terminal in the Start menu.
- Right-click it and select Run as administrator.
- Go to the script location and run the script:
cd C:\PS
.\my_script.ps1
Alternatively, you can create a shortcut that launches PowerShell as Administrator and executes a specific script.
Create desktop shortcut that always runs elevated interactive PowerShell console
You can create a desktop shortcut that always runs an elevated interactive PowerShell console.
- Right-click anywhere on the desktop and click New โ Shortcut.
- Type powershell.exe (Windows PowerShell) or pwsh.exe (PowerShell 7+) and click Next.

- Type the shortcut name and click Finish.
- Open the shortcut properties and click Advanced. Check the โRun as administratorโ box and save changes.

Keep in mind that powershell.exe refers to Windows PowerShell 5.1 (Windows-only, legacy engine, no new feature development) and pwsh.exe refers to PowerShell 7+ (cross-platform, actively developed, based on .NET 6/7/8 runtime depending on version)
Key differences:
- Modules. Windows PowerShell uses built-in Windows-compatible modules (e.g. legacy ActiveDirectory, ServerManager). PowerShell 7 uses a compatibility layer (Windows Compatibility Module/implicit remoting) for many Windows-only modules.
- Execution policy. Both Windows PowerShell and PowerShell 7 support Process, CurrentUser, and LocalMachine execution policy scopes. PowerShell 7 provides more consistent behavior across platforms, but execution policy is not a security boundary.
- Remoting. Windows PowerShell uses WinRM (WSMan) by default. PowerShell 7 supports WinRM but introduces SSH-based remoting as the preferred modern and cross-platform option.
Every time you use the new shortcut to start PowerShell, it will run as an administrator.
Creating a Shortcut That Runs a Specific Script as Administrator
You can also create a shortcut that launches a specific PowerShell script with elevated privileges. Follow the steps below:
- Right-click the desktop and select New โ Shortcut.
- In the location field, enter:
powershell.exe -NoProfile -File "C:\Scripts\MyScript.ps1"
- Click Next, provide a shortcut name, and click Finish. The script must comply with the effective PowerShell execution policy. If script execution is restricted on the machine, the script may fail to start. In enterprise environments, you need to config an appropriate execution policy through Group Policy/other management tools and consider signing admin scripts. For example, RemoteSigned allows locally created scripts to run while requiring downloaded scripts to be signed/unblocked according to the policy.
- Open the shortcut Properties, click Advanced, and enable Run as administrator.
- Use the shortcut to launch the script with elevated privileges.
To launch a specific PowerShell script with elevated privileges from another PowerShell session, use the following command:
Start-Process powershell.exe -Verb RunAs -ArgumentList '-NoProfile -File "C:\ps\my_script.ps1"'
How to Check if a PowerShell Script is Running as Administrator
When you run a PowerShell script, you may need to check that it is running in elevated mode. Add the following block code at the beginning of the script to indicate that this script is being run as an administrator:
if (-not (
[Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
throw "This script must be run as Administrator"
}
In production scripts, you may prefer Write-Error and exit 1 instead of throw to provide cleaner output.
Require Administrator Rights with Requires
PowerShell provides a built-in way to prevent a script from running without admin privileges. You can add the following directive at the beginning of your script:
#Requires -RunAsAdministrator
Get-Service
When a user runs the script without elevated privileges, PowerShell stops execution and displays an error message before any script code is executed.
The #Requires -RunAsAdministrator directive is the simplest way to enforce elevation requirements and is often preferred over manually checking the current security context. Unlike manual elevation checks, #Requires is evaluated before any script code runs.
Automatically Relaunch a PowerShell Script as Administrator
Instead of displaying an error when a script is not running with elevated privileges, you can automatically relaunch the script as Administrator. This method is commonly used in admin scripts because it prompts for elevation only when required and then continues execution in the elevated PowerShell session. Here is a script:
if (-not (
[Security.Principal.WindowsPrincipal]
[Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole(
[Security.Principal.WindowsBuiltInRole]::Administrator
)) {
Start-Process powershell.exe `
-Verb RunAs `
-ArgumentList "-NoProfile -File `"$PSCommandPath`" $($args -join ' ')"
exit
}
The current non-elevated script instance exits immediately after launching the elevated copy. If the script accepts parameters, they must also be passed to the elevated process. Otherwise, the elevated instance will start the script without the parameters supplied during the original launch.
The $PSCommandPath automatic variable contains the full path to the currently running script. If the script is started without admin privileges, PowerShell displays a UAC prompt and relaunches the same script in an elevated session.
Run PowerShell Script as Administrator Without UAC Confirmation
In all of the cases described above, running the PowerShell script as an administrator requires UAC elevation confirmation. To run a PowerShell script as an administrator without the UAC prompt, you must create a special scheduled task with Highest Privileges option enabled. This works because the elevation decision is made once at task creation time (when you configure the task) rather than at execution time. Windows trusts tasks configured this way to run elevated without prompting.
- Open the Task Scheduler (taskschd.msc) and click โCreate a task.โ

- Under the General tab, configure the following:
- The name is RunMeAsAdmin.
- Select Run only when user is logged on.
- Check Run with highest privileges.
For fully unattended execution, you should consider running the task under SYSTEM account. Note that running under SYSTEM grants extensive local privileges but may behave differently for network resources, mapped drives, and user-specific environment variables. You should test scripts thoroughly before deploying under this account.
- Switch to the Actions tab and click New.
- In the New Action window:
- Type powershell.exe for Windows PowerShell or pwsh.exe for PowerShell Core in the โProgram/scriptโ box.
- Type -NoProfile -File C:\ps\my_script.ps1 inside the โAdd argumentsโ.
Security note. You should avoid using -ExecutionPolicy Bypass as a default in production environments. If your organization uses execution-policy controls, follow those policies and consider signing admin scripts. You should use Bypass only when there is a specific, understood reason to override the configured policy.
- Click OK to close the New Action window.
- Click OK to save the new task.
- Once the task is created, select it from the list and click Run in the Actions pane. This will run your PowerShell script elevated without UAC prompt.

- Or you can trigger it from PowerShell by running the below command:
Start-ScheduledTask -TaskName <task name>

This approach allows PowerShell scripts to run in the elevated non-interactive mode without triggering the UAC prompt. For interactive administration, the simplest method is to start PowerShell/Windows Terminal as Administrator. For automation cases where no user interaction is possible, you should prefer running Scheduled Tasks with highest privileges.
Why can’t I right-click a .ps1 file and select “Run as administrator”?
Windows does not provide a built-in Run as administrator option for PowerShell script files in File Explorer. To run a script elevated, start PowerShell or Windows Terminal as Administrator and execute the script manually.
How do I open an elevated PowerShell session in Windows Terminal?
Right-click Windows Terminal and select Run as administrator. Any PowerShell session started within that Terminal window will run with elevated privileges.
Can I create a shortcut that always opens PowerShell as Administrator?
Yes.
- Create a new desktop shortcut pointing to powershell.exe or pwsh.exe.
- Open the shortcut Properties.
- Click Advanced.
- Enable Run as administrator.
The shortcut will always launch an elevated PowerShell console.
Can I run a PowerShell script as Administrator without a UAC prompt?
Yes. The recommended method is to create a Scheduled Task configured with Run with highest privileges enabled.




which leaves us with the only both uncovered and the only practical application:
how to actually execute a powershell script in elevated mode without user’s input.
cause the idea behind writing a script is automation and the idea behind automation is that user’s input is not required.
I wish you find out and are willing to share the answer you got….because I am in the same boat
I am exactly facing this issue, I cant find a way to prompt the user to concede administrator privileges
It works just fine in my pipelines. Make sure that the Powershell is in the taskbar and properties are Advanced->Run as admin
In your runs put the line he referred to run: |
#Requires -RunAsAdministrator
Start-Process -Wait -FilePath ..