Post

Windows Terminal: Run PowerShell as Administrator

This post is from 2021 and may be out of date. Windows Terminal now supports this natively (Run this profile as Administrator in the profile settings), and Windows 11 24H2 has a built-in sudo.

from GitHub: Windows Terminal Issue 691, GitHub: gerardog/gsudo

Currently, Windows Terminal does not support running individual tabs as Administrator.
There is an elegant workaround employing a third-party application, gsudo.

  1. Start PowerShell as Administrator.

  2. Run:
    1
    
     choco install gsudo -y 
    

    Note: you don’t need chocolatey; refer to the gsudo source.

  3. Open Windows Terminal -> Settings -> Add new

  4. Under Command line add this:
    1
    
     pwsh.exe -Command "gsudo pwsh"
    

    Note: pwsh is for PowerShell 7 (if you have it). This works equally well for the default PowerShell: just replace pwsh with powershell.

  5. Change the tab icon to distinguish it from the non-elevated version.
    Here’s a red one.
This post is licensed under CC BY 4.0 by the author.