Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.
Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.

Many ways to query AD users

There are multiple good PowerShell options to query an Active Directory user object.   Below are three code snippets which all locate an AD user.   Cheers!

 

Option 1- Get-ADUser Login

Get-ADUser jsmith -Properties *

 

Option 2- Get-ADUser Filter

Get-ADUser -Filter {Surname -like 'W*'} -Properties *

 

Option 3 – LDAP Directory Searcher

$strFilter = "(&(objectCategory=User)(samAccountName=jsmith))"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults){$objItem = $objResult.Properties; $objItem.name}

 

Option 4 – DSA.MSC

  1. Open Active Directory Users and Computers.
  2. Right-click the domain object and select Find.
IC125695
  1. Active Directory Users and Computers Select Find
  2. Click the drop-down list next to Find, and then select Custom Search.
IC25246
  1. From the next screen, select the Advanced tab.
  2. Type the appropriate LDAP statement under Enter LDAP query.

 

Option 5 – LDP.EXE

  1. Download from https://www.microsoft.com/en-us/download/details.aspx?id=15326
  2. On the Browse menu, click Search.
  3. The Search dialog box opens.
  4. To search for all users that have a first name of John and a last name of either Smith or Jones, type the following in the Filter field:
  5. (&(objectClass=user)(givenName=John)(|(sn=Smith)(sn=Jones))))
Image result for ldp.exe

 

 

References

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲