How to `sudo` on Powershell - Windows executor

Windows Powershell doesn't have sudo - some commands needs to be run as an administrator  Powershell has no concept of it.


One solution we can use is Start-Process command: The following line is the example of this command.

Start-Process wpr -verb runAs -Args "-start GeneralProfile"

This is calling wpr (Windows Performance Recorder) as an administrator and passing necessary arguments with -Args flag.  However in this case, the challenge is that we don't see the output because theoretically, since it starts a new shell somewhere.


The other way you can think is scoop ( which enables the commands equivalent to the one in Linux. You can install by following way:

iex (new-object net.webclient).downloadstring('')
set-executionpolicy unrestricted -s cu -f
scoop install sudo

By installing this, you can use sudo just like you're in Linux. However with this, it's basically doing the same thing with the above so it's not possible to see the output anyway. (You can see the script inside here:

Was this article helpful?
15 out of 40 found this helpful



Article is closed for comments.