locked
adsisearcher return legacyexchangedn for user RRS feed

  • Question

  • I'm trying to write a script to get the legacyexchangedn for a specific user using the adsisearcher but cannot figure out how to get this accomplished.  I'm trying the code below, which I know is wrong.  Any suggestions

    $searcher = [adsisearcher]""
    $searcher.propertiestoload.addrange(('name','legacyExchangeDN'))
    $searcher.filter = "name=username"
    $searcher.findone()
    
    Path                                                        Properties
    ----                                                        ----------
    LDAP://CN=Username,OU=People,DC=tst,DC=doman,DC=com     {name, adspath}


    Monday, October 5, 2015 4:33 PM

Answers

  • You could use Get-ADObject and the -IncludeDeletedObjects parameter.

    Get-ADObject -Filter {Name -eq "Joe Smith} -Properties legacyExchangeDN -IncludeDeletedObjects

    This assumes that attribute is maintained in deleted objects.

    Richard Mueller - MVP Directory Services


    Tuesday, October 6, 2015 2:31 AM

All replies

  • $username='Joe Smith'
    $searcher = [adsisearcher]"name=$username"
    $searcher.propertiestoload.addrange(@('name','legacyexchangedn'))
    $searcher.findone()|
    	select @{N='Name';E={$_.properties['name']}},
    		@{N='LegacyExchanegDN';E={$_.properties['legacyexchangedn']}}
    


    \_(ツ)_/

    Monday, October 5, 2015 5:31 PM
  • Thanks jrv. One more thing I guess I forgot to mention would be that I am also trying to get this information out of the Deleted Objects OU.  Is that even possible?
    Monday, October 5, 2015 8:08 PM
  • Good question.  I see no reason why not but many properties are not kept when an item is deleted.  All I can say is try it.


    \_(ツ)_/

    Monday, October 5, 2015 8:10 PM
  • Gave it a try and it doesnt appear to be working.  Weird thing is if I use the ldp.exe utility and view the object I can still see the legacyexchangedn information, but it wont display using powershell.
    Monday, October 5, 2015 8:16 PM
  • Many properties are hidden so they can be inactivated.  Look for a collection on the object that may contain these hidden properties.

    Remember that the property names a case sensitive and must always be specified in all lowercase.


    \_(ツ)_/

    Monday, October 5, 2015 8:18 PM
  • Guess it also helps if I use the correct powershell windows with the proper permissions to read the Deleted Objects OU.
    Monday, October 5, 2015 9:16 PM
  • You could use Get-ADObject and the -IncludeDeletedObjects parameter.

    Get-ADObject -Filter {Name -eq "Joe Smith} -Properties legacyExchangeDN -IncludeDeletedObjects

    This assumes that attribute is maintained in deleted objects.

    Richard Mueller - MVP Directory Services


    Tuesday, October 6, 2015 2:31 AM