If User Exists?
Getting a simple script to check if an AD user exists has been a nightmare. I wanted something simple and straightforward and I finally found it.
$userobj = $(try {Get-ADUser $user} catch {$null})
if ($userobj -ne $null) {
"$user exists"
}
else {
"$user not found"
}
Another options would be to use dsquery:
if (dsquery user -samid $user) {
"$($user.name) exists"
}
else {
"$($user.name) not found"
}
These are the simplest options I can find.