Running a command as Administrator using PowerShell?

chrips picture chrips · Oct 7, 2011 · Viewed 1M times · Source

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.

Answer

Shay Levy picture Shay Levy · Oct 7, 2011

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

https://docs.microsoft.com/powershell/module/Microsoft.PowerShell.Management/Start-Process