powershelladministrator

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.


Solution

  • 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