Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In a PowerShell script, how can I check if I'm running with administrator privlieges?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

Have a look at:


share|improve this answer
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal( [Security.Principal.WindowsIdentity]::GetCurrent() ) &{ if ($currentPrincipal.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator )) { (get-host).UI.RawUI.Backgroundcolor="DarkRed" clear-host write-host "Warning: PowerShell is running as an Administrator.`n" } –  davey Dec 17 '09 at 20:16
thanks that worked! –  Michael Kelley Dec 17 '09 at 20:30
function Test-Administrator  
    $user = [Security.Principal.WindowsIdentity]::GetCurrent();
    (New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)  

Execute the above function. IF the a result is True, the user has admin privileges.

share|improve this answer
This only determines if the user running the script is an administrator on the machine -- and not if the script is currently being executed with administrative privileges. In other words, this will still return true even if the user did not use "run as administrator" to launch the command shell. –  Holistic Developer Oct 17 at 19:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.