How to run PowerShell as an administrator?

Open the PowerShell console on Windows 10 via the search bar, shortcut, or pinned taskbar items. Exe process starts in unprivileged mode. In this mode, you won’t be able to make any changes or perform administrative tasks.

In this article, we go through few easy steps to run a PowerShell console or script as an administrator.

Using windows 10 search bar

  1. click on the start button or press the window key on your keyboard.
  2. Type PowerShell in the search bar
  3. Right click on the windows PowerShell icon
  4. Select Run as administrator.
  5. A UAC window will appear, now 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.

  1. Press the Windows+X on your keyboard
  2. Right click the start button
  3. Select Windows PowerShell (admin)

Using taskbar shortcut

If you often run the PowerShell console as an administrator, then you can create a shortcut to start the PowerShell in the elevated mode automatically.

  1. Right click on the PowerShell icon in the start menu. Select pin to taskbar.
  2. Right click on the PowerShell icon in the taskbar, select Windows PowerShell > right click > properties.
  • Click on Advance button and enable the Run as Administrator option.
  • Click OK twice.

Now PS console will always open in privileged mode. You just have to click on the PowerShell icon in the taskbar.

How to Run a PowerShell Script as an Administrator?

When you run any PowerShell script in an elevated session, it runs as an administrator.

You can run a PowerShell script file as an administrator with the following command:

Start-Process PowerShell -verb run as -ArgumentList “-file C:\PS\Scripts\myPSScript.ps1”

Hint: make sure the PowerShell Executive Policy on your computer is not blocking PowerShell scripts from running.

You can open the console as an administrator by the following command:

PowerShell Start-Process PowerShell -Verb runs

You can execute this command in the cmd.exe command prompt, PowerShell, or by using the Run Feature.

Check if PowerShell id running as Administrator

If your PowerShell.exe console od running with administrator privileges, the window title will say Administrator: Windows PowerShell

In some PowerShell scripts, it is necessary to verify that the script is running with administrator privileges before running any action.

Run the Command:

[Security.Principal.WindowsIdentity]::GetCurrent().Groups -contains ‘S-1-5-32-544’

If the command returned true, then the PowerShell session started with administrator permissions.

In PowerShell v4.0 and newer, you can use a special statement at the begging of your scripts to prevent a PowerShell script from running as a regular (non-administrator) user.

#Requires -RunAsAdministrator

If the script 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.

Leave a Reply

Your email address will not be published. Required fields are marked *




Enter Captcha Here :