active directory - Powershell LDAP - physicalDeliveryOfficeName not showing up -


pretty straight forward question: i'm not sure why "physicaldeliveryofficename" property not showing in output. i've read non-standard property, have not been able find way add it. works except missing "physicaldeliveryofficename." help!

$dom = 'ldap://ou=xx;dc=xx;dc=local' $root = new-object directoryservices.directoryentry $dom  $selector = new-object directoryservices.directorysearcher $selector.searchroot = $root  $selector.pagesize = 1000 $adobj= $selector.findall() | {$_.properties.objectcategory -match "cn=person"}   (get-content c:\filename.txt) | foreach-object ` { `   foreach ($person in $adobj){    $prop=$person.properties   if ($prop.cn -like "*" + $_.substring(1, 3) + "*")     {      $s1 = $_ -replace $_.substring(0, 4), $prop.cn       $s2 = $s1 -replace "ad_dept", $prop.department      $s3 = $s2 -replace "ad_branch", $prop.physicaldeliveryofficename       add-content c:\filename2.txt $s3     }   } } 

the ad_dept , ad_branch placeholders in original file.

edit

i read through jpblanc's answer , did more research , ended working example. key seems in specifying properties load. thanks!

$strfilter = "(&(objectclass=person)(department=*))" $objdomain = new-object system.directoryservices.directoryentry $objou = new-object system.directoryservices.directoryentry("ldap://ou=xx;dc=xx;dc=local") $objsearcher = new-object system.directoryservices.directorysearcher $objsearcher.searchroot = $objou $objsearcher.pagesize = 1000  $objsearcher.filter = $strfilter $objsearcher.searchscope = "onelevel"  $colproplist = "cn","department","physicaldeliveryofficename" foreach ($i in $colproplist){$objsearcher.propertiestoload.add($i)}  $colresults = $objsearcher.findall()  remove-item \\server\ftproot\folder\filename.modified (get-content \\server\ftproot\folder\filename) | foreach-object ` { `   foreach ($person in $colresults){    $prop = $person.properties   if ($prop.cn -like "*" + $_.substring(1, 3) + "*")     {      $s1 = $_ -replace $_.substring(0, 4), $prop.cn       $s2 = $s1 -replace "ad_dept", $prop.department      $s3 = $s2 -replace "ad_branch", $prop.physicaldeliveryofficename       add-content \\server\ftproot\folder\filename.modified $s3      break     }   } } 

much things have said there.

1. presence of attribute

for attribute queried, first must present in schema of directory. schema defines types , attributes directory entries can contain. in schema attribute has defined "may be" or "must " present in type. example objectclass attribute must present in types.

if have in schema of windows 2k8 r2, can see attribute :

enter image description here

now if use apache directory studio can see physicaldeliveryofficename present 12 types (11 on normal server forget slxauteur)

enter image description here

conclusion of first part : (if have enough rights) set attribute on user or inetorgperson.

2. way search attribute

you'll find here under sample of usage of directory searcher. add code modify physicaldeliveryofficename attribute on specified user.

$dn = new-object system.directoryservices.directoryentry ("ldap://192.168.183.138:389/dc=societe,dc=fr","administrateur@societe.fr","blabla")  # users $rech = new-object system.directoryservices.directorysearcher($dn) $rc = $rech.filter = "((objectcategory=person))" $rc = $rech.searchscope = "subtree" $rc = $rech.propertiestoload.add("distinguishedname"); $rc = $rech.propertiestoload.add("samaccountname");   $rc = $rech.propertiestoload.add("ipphone");   $rc = $rech.propertiestoload.add("telephonenumber"); $rc = $rech.propertiestoload.add("memberof"); $rc = $rech.propertiestoload.add("distinguishedname"); $rc = $rech.propertiestoload.add("physicaldeliveryofficename"); # attribute   $liste = $rech.findall() foreach ($usr in $liste)  {   # write-host $usr.properties["samaccountname"]   if ($usr.properties["samaccountname"] -eq "massin")   {     write-host $usr.properties["distinguishedname"]     $dnuser = new-object system.directoryservices.directoryentry ("ldap://192.168.183.138:389/$($usr.properties["distinguishedname"])","administrateur@societe.fr","blabla")     $dnuser.put("physicaldeliveryofficename", "1 rue de la source")     $res = $dnuser.setinfo()     $res   } } 

here result :

enter image description here

remarks : directory search

  1. the node begin search
  2. the attributes want (it's not mandatory, it's best practice) if no give them can't sure retrieved.
  3. the depth (base, onelevel, subtree)
  4. the filter

if attribute not queried or empty, not present in result


Comments