PowerShell – Test Admin Status of Current User

email me

Function Test-AdminStatus
{
$WinIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$WinPrincipal = New-Object Security.Principal.WindowsPrincipal $WinIdentity
#ACCOUNT
$WinPrincipal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}

Clear-Host

# Test Function
if (Test-AdminStatus) {"$env:UserName : True"} Else {"$env:UserName : False"}


Output

 


Notes

[enum]::getnames("security.principal.WindowsBuiltInRole")

 

Other accounts you can test for

User
Guest
PowerUser
AccountOperator
SystemOperator
PrintOperator
BackupOperator
Replicator

 

tags: MrNetTek