Search for a User with a Specified First Name and Last Name

Sample script that searches Active Directory for a user with the first name Ken and the last name Myer. Both the givenName and sn attributes are replicated to the Global Catalog.

Add to favorites
Active Directory
E-mail Twitter Digg Facebook
  • Can I use this script to display Extensionattributes from Attribute Editor?
    2 Posts | Last post June 16, 2014
    • $strFilter = "(&(objectCategory=User)(Name=Cihat Kaya))"
      $objDomain = $objOU
      $objOU = New-Object System.DirectoryServices.DirectoryEntry("LDAP://OU=De Lier,dc=building,dc=com")
      $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
      $objSearcher.SearchRoot = $objDomain
      $objSearcher.PageSize = 1000
      $objSearcher.Filter = $strFilter
      $objSearcher.SearchScope = "Subtree" #Kies uit Base, OnLevel, Subtree. (Hoe diep moet hij binnen de domain zoeken?)
      $colProplist = "name", "mail","title", "extensionAttribute1"
      foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
      $colResults = $objSearcher.FindAll()
      foreach ($objResult in $colResults)
          {$objItem = $objResult.Properties
               "Name: " + $
               "E-mail: " + $objItem.mail
               "Job Title:" + $objItem.title
               "Building": " + $objItem.extensionAttribute1
      Works well with varchar but not with attribute out of Attribute Editor or white attributes that contains numbers like telephone Number.
      My question is how can I get it to work so I can call those attribute as well and display them . I have read
      I seen on this site it worked but they use 
      Which if I do use this as well I get an error : Unexpected token '-Host' in expression or statement.
      Sadly I am not that experience powershell user to understand the error output.
    • I found away around this I search more on google and found an other solution to achieve this.