How to `sudo` on Powershell - Windows executor

Run Commands As Superuser/Admin

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


Start-Process Command

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, it starts a new shell somewhere else.


Install sudo Package With Scoop

Another solution is to use 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, 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:


Additional Resources

Was this article helpful?
27 out of 72 found this helpful



Article is closed for comments.