Is there an equivalent "sudo" command in PowerShell on Ubuntu?

I would like to try and use PowerShell as my default shell on Ubuntu 18.04, however with bash I can opt to run some commands as sudo and I'm not sure how I'd be able to do that with PowerShell as it doesn't have sudo as a concept.

In PowerShell on Windows you have to run the shell as an administrator. If I set my default shell to PowerShell I worry that I wouldn't be able to run the commands I might need to without sudo, would I have to drop into bash? I don't want to run the default shell as an administrator by default.

1

2 Answers

If I understand correctly, you would like to use PowerShell in Ubuntu but you will need the sudo command. You can do bash -c "sudo <bash command>". sudo usually doesn't work in PowerShell because it is a Unix Executable so you will need to use sudo with a Bash command. As pointed out by others, runas is your best option in PowerShell. Note that you will need Ubuntu installed or some other method of accessing Bash in CMD/PowerShell. I think you already have the Ubuntu command line installed using WSL so you should be fine if that is the case.

There is no sudo in PowerShell natively. That is what -RunAs is for, but generally not the same thing either.

There are modules that are wrappers that try to emulate it. Yet, not the same thing. These have been around before PSCore (PowerShellv6/7 existed), so no guarantee that they will work in those versions.

Find-Module -Name '*sudo*' | Format-Table -AutoSize
<#
# Results
Version Name Repository Description
------- ---- ---------- -----------
2.1.0 Sudo PSGallery Use functionality similar to sudo in PowerShell. GitHub:
1.4.0 PSSudo PSGallery Function for executing programs with adminstrative privileges
#>

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like