If Statements and AD Objects

less than 1 minute read

Check if AD Object returned is group or user:

if ($adObject.objectClass -eq "group"){

}

if ($adObject.objectClass -eq "user"){

}

Check if multiple users returned from a get-aduser query:

if ($User -is [system.array]){
    # Throw an error, multiple users returned
}
elseif ($User -is [Microsoft.ActiveDirectory.Management.ADAccount]){
    # do something
}