Skip to main content

PowerShell function to check if a user is in the local Administrators group.

function CheckIfUserIsAdmin($username)
{
    $computer = [ADSI]("WinNT://$env:computername,computer")
    $group = $computer.psbase.children.find("Administrators")
    
    $colMembers = $group.psbase.invoke("Members") | ForEach-Object { $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null) }

    $bIsMember = $colMembers -contains $username
    if ($bIsMember)
    {
        return $true
    }
    else
    {
        return $false
    }
}