Posts

Showing posts from August, 2014

PowerShell script to check user in Active Directory

Image
 Here is a quick PowerShell script to check for user in present in Active Directory. $user = "JohnDoe" $searcher =  [ADSISearcher]"(sAMAccountName=$user)" $results =  $Searcher.FindOne() If ($results -eq $Null)      {"User does not exists"} Else      {"User Exists"} Same can be done using the user email $email = "JohnDoe@company.com " $searcher =  [ADSISearcher]"(mail=$email)" $results =  $Searcher.FindOne() If ($results -eq $Null)      {"User does not exists"} Else      {"User Exists"} It can be extended more to retrieve more information on the user. For example if the user account is active in AD. $email = "JohnDoe@company.com" $searcher =  [ADSISearcher]"(&(mail=$email)(userAccountControl:1.2.840.113556.1.4.803:=2))" $results =  $searcher.FindOne() If ($results -eq $Null)      {"User account is enabled"} Else      {"User account is disabl