Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a command as Administrator using PowerShell?

You know how if you're the administrative user of a system and you can just right click say, a batch script and run it as Administrator without entering the administrator password?

I'm wondering how to do this with a PowerShell script. I do not want to have to enter my password; I just want to mimic the right-click Run As Administrator method.

Everything I read so far requires you to supply the administrator password.

like image 735
chrips Avatar asked Oct 07 '11 17:10

chrips


People also ask

How do I Run a command prompt as administrator in PowerShell?

Step 1: Open the Command Prompt, and type the PowerShell as a command, then press Enter key. Step 2: Now, the command prompt will turn to Windows PowerShell. Step 3: Type the command start-process PowerShell -verb runas and press "enter" key. Step 4: It will bring up an elevated Windows PowerShell as an administrator.

How do I Run a command prompt as administrator?

Using the run command You can also open a command prompt using a run-box (Windows + R). To do so, open a run-box, write cmd , and press Control + Shift + Enter to open the command prompt as an administrator.

How do I Run PowerShell with administrator privileges?

Select “Run as administrator“. If you're running Windows 7, Vista or XP, in order to start Windows PowerShell with administrator privileges, you need to click Start -> All Programs -> Accessories, point to Windows PowerShell, right-click Windows PowerShell, and select Run As Administrator.


1 Answers

If the current console is not elevated and the operation you're trying to do requires elevated privileges then you can start powershell with the Run as Administrator option :

PS> Start-Process powershell -Verb runAs 

Microsoft Docs: Start-Process

like image 106
Shay Levy Avatar answered Sep 19 '22 08:09

Shay Levy