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: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process. 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('https://get.scoop.sh')
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: https://github.com/lukesampson/psutils/blob/master/sudo.ps1)
Comments
Article is closed for comments.