When you open the PowerShell console on Windows via the Search bar, shortcut, or pinned taskbar item, the powershell.exe process starts in unprivileged mode. In this mode, you won’t be able to make system changes or perform administrative tasks. In this article, we’ll walk through a few easy ways to run a PowerShell console or script as an administrator.
Run PowerShell as Administrator Using Windows Search Bar
- Click on the Start button or press the Windows key on your keyboard;
- Type powershell in the search field;
- Right-click on the Windows PowerShell icon and select Run as administrator (or select this item in the right pane);
- A UAC window will appear, in which you need to confirm the start of the process in the elevated mode.
There is also a separate item for starting PowerShell with elevated permissions in the Win+X menu of Windows 10 and 11. Just press Windows + X on your keyboard or right-click the Start button and select Windows PowerShell (Admin).
Create Taskbar Shortcut to Run PowerShell as Administrator
If you often run the PowerShell console as an administrator, you can create a shortcut to start the PowerShell in elevated mode automatically.
- Find the PowerShell icon in the start menu, right-click on it and select Pin to taskbar;
- Right-click on the PowerShell icon in the taskbar, select Windows PowerShell > right-click > Properties;
- Click the Advanced button and enable the Run as administrator option;
- Click OK twice.
Now, when you click on the PowerShell icon in the taskbar, the PS console will always open in privileged mode.
How to Run a PowerShell Script as Administrator?
When you run any PowerShell script (PS1 file) in an elevated session, it runs as an administrator. Or you can run a PowerShell script file as an administrator with the following command:
Start-Process powershell -verb runas -ArgumentList "-file C:\PS\Scripts\myPSScript.ps1"
Hint. Make sure the PowerShell Execution Policy on your computer is not blocking PowerShell scripts from running.
You can open the console as an administrator with the following command:
powershell Start-Process powershell -Verb runAs
You can execute this command in the cmd.exe command prompt, PowerShell, or using the Run feature.
When you run this command, a UAC window appears asking you to confirm privilege escalation:
User Account Control
Do you want to allow this app to make changes to your device?
Running PowerShell as Administrator without UAC Prompt?
It is not recommended to disable UAC on Windows. Therefore, you can implement one of the following scenarios to run a PowerShell console with administrator rights without a UAC prompt. It is assumed that your account is a member of the local Administrators group. Otherwise, Windows will ask you to enter the Administrator password on a UAC prompt.
- Run powershell.exe from Task Manager.
- Create a new scheduled task with the checkbox “Run with highest privileges” enabled.
In the first case:
- ) Open the Task Manager (Ctlr+Alt+Esc or right-click on the taskbar and select Task Manager);
- Select the menu item File > Run new task;
- In the Open window, type powershell and enable the option Create the task with administrative privileges;
- Click OK. The PowerShell console should open without a UAC prompt.
Now let’s create a scheduled task to run PowerShell as administrator:
- Open the Task Scheduler console (taskschd.msc);
- Select Action > Create Task;
- Specify the task name PowerShellAdminTask;
- Check the option Run with highest privileges;
- Select Windows 10 in the Configure form;
- Uncheck the Hidden checkbox;
- Go to the Actions tab and select New > Start a program;
- Copy the following line to the Program field C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe;
- Save your task.
Now, to run the PowerShell console as an administrator without a UAC prompt, select the PowerShellAdminTask task in the Task Scheduler console, right-click on it, and select Run.
Or you can run the job from a non-elevated command prompt with the command:
schtasks.exe /run /tn PowerShellAdminTask
You can use the Task Scheduler solution to run PowerShell scripts as an administrator without the user’s input. In this case, in the Add argument field, you need to specify the path to your PowerShell script in the following format:
-executionpolicy bypass -file c:\ps\scripts\myposhscript.ps1
In this case, the script will be run as an administrator, even if the PowerShell Execution policy is enabled, which blocks unsigned scripts from running.
Check if PowerShell is Running as an Administrator
If your powershell.exe console is running with administrator privileges, the window title will say Administrator: Windows PowerShell.
In some PowerShell scripts, verifying if the script is running with administrator privileges is sometimes necessary before starting any action.
Run the command:
[Security.Principal.WindowsIdentity]::GetCurrent().Groups -contains 'S-1-5-32-544'
If the command returned True, then this PowerShell session was started with administrator permissions.
In PowerShell v4.0 and newer, you can use a special statement at the beginning of your scripts to prevent a PowerShell script from running as a regular (non-administrator) user:
If a script with such a statement is executed in a non-elevated PowerShell process, you will receive an error message:
The script ‘test_admin_script.ps1’ cannot be run because it contains a “#requires” statement for running as an Administrator. The current Windows PowerShell session is not running as Administrator. Start Windows PowerShell by using the Run as Administrator option, and then try running the script again.