Admin Privileges Enabled?

by Feb 16, 2012

If you want to know whether your script has currently full Administrator privileges, here is an (admittedly long) one-liner that tells you:

(New-Object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)

Try executing this line in a regular PowerShell and then in an elevated shell, and check out the difference. Or, create your own console prompt which turns red when you have admin privileges:

function prompt {
if ((New-Object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) {
  Write-Host (Admin) ForegroundColor Red -NoNewLine
  $user = Administrator: 
} else {
  $user = ‘’
$Host.UI.RawUI.WindowTitle = $user $(Get-Location)

Twitter This Tip! ReTweet this Tip!