Sudo in PowerShell: Get Administrator Privileges With gsudo
Are you exhausted from the repetitive process of right-clicking to execute "Run as administrator" when you need an elevated PowerShell terminal? Imagine if there was an effortless method to elevate your current Windows shell. While the Linux sudo command is widely recognized, you might not be aware of its incredible Microsoft Windows counterpart: gsudo! In this guide, I'll walk you through a few simple steps to install and set up this fantastic Windows application for seamless terminal elevation to the Administrator account.
Installing gsudo With WinGet
We can simply install the gsudo package using the Windows Package Manager (winget). If you’re unsure if you have winget installed I cover this awesome Windows tool in a previous blog post.
The package we are going to install is the geradog.gsudo application. We can perform a simple search for this package using winget. To find the correct Windows package we’ll use the winget search command to find the appropriate package.
Adding gsudo To the Windows Path Variable
In an elevated powershell terminal we need to ensure that Windows has the path to gsudo.exe. We can accomplish this as a persistent change with the following series of commands.
First let’s save the current path using the following Get-ItemProperty command.
Next let’s append the path to gsudo.exe to our current path.
And finally let’s set this new updated path with the Set-ItemProperty command.
If successful we should see the correct path to gsudo appended to our Windows path variable.
Running gsudo
Once we have added the location of gsudo.exe to our Windows PATH variable we can run gsudo from our PowerShell terminal to elevate the our prompt. We can simply run gsudo from the PowerShell terminal
gsudo UAC confirmation
When we first run gsudo we will encounter a User-Access-Control (UAC) prompt. In order to elevate our prompt we need to allow this application to make changes.
Great! Our PowerShell terminal is now running as an Administrator. Let’s explore how we can get help with running gsudo.
Getting Help with gsudo Usage
Like most command-line tools we can use the help command to see gsudo usage information as well as common syntax options.
If you have any questions or have issues feel free to message me on social media.