Powershell – In a PowerShell script, how can I check if I’m running with administrator privileges

powershell

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

Best Answer

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

(from Command line safety tricks)