When you open the PowerShell console on Windows 10 via 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 10 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. 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 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 cmd.exe command prompt, PowerShell, or using the Run feature.
Check if PowerShell is Running as Administrator
If your powershell.exe console is running with administrator privileges, the window title will say Administrator: Windows PowerShell.
In some PowerShell scripts, it is sometimes necessary to verify that the script is running with administrator privileges 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 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.