Search code examples
windowspowershelluac

How can I find out whether my current PowerShell console runs elevated (as administrator)


Is there a cmdlet or some other way to find out whether my current PowerShell console runs as administrator, i.e. elevated?


Solution

  • Try this code:

    if ((New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { 
    Write-Host "Elevated." 
    } else { 
    Write-Host "Not elevated." 
    }
    

    Attribution: https://www.itprotoday.com/powershell/check-elevation-powershell