Test Admin Privileges

by Nov 22, 2010

If you want to systematically test whether you currently have Administrator privileges, you can use this function:

function Test-Admin {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = new-object Security.Principal.WindowsPrincipal $identity
$principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}

It will return $true if you do have Administrator rights, else $false.

Twitter This Tip!
ReTweet this Tip!