Testing Administrator Privileges

by Sep 24, 2013

To test whether a script is run by an Administrator with full privileges (UAC elevated), here is an unusual approach that illustrates the enormous flexibility in PowerShell:

function Test-Admin { [bool]((whoami /groups) -match "S-1-16-12288") } 

It basically tests whether the current user is member of the high integrity group (S-1-16-12288) which is only the case for elevated admins.

Twitter This Tip! ReTweet this Tip!