CLSolorzano
asked on
Powershell script to retrieve display name of objects in an AD container
Does anyone know of a powershell commandlet/script that will retrieve and output to a .csv file, the display names of all objects in a specific AD container?
If you want a recursive list... it will be slightly more complicated.
$OU = [ADSI]"LDAP://<container path>"
$searcher = new-object System.DirectoryServices.DirectorySearcher($OU,"Objectclass=*")
$searcher.pagesize = 1000
$searcher.findall() | %{$_.psbase.properties['cn'][0]}
You can use export-csv to output to a csv file, but you only want one property so a CSV doesn't make sense. Just use out-file
ASKER
Great, that worked, I am having trouble exporting though. The system hangs with: >> and a blinking cursor and never gets done. when I user the following command:
$OU = [ADSI]"LDAP:// OU=Exchange Generics,DC=AD,DC=SANNET,D C=GOV
$OU.psbase.children | %{$_.displayname} | select-object displayname |
@{name="displayname";expre ssion={$_. Identity.T oString(). Split("\") [0]}}, Displayname, Identity | Export-csv -path:"C:\displaynames.csv "
Can someone tell me what I am doing wrong? I get no errors, the command just never completes.
$OU = [ADSI]"LDAP:// OU=Exchange Generics,DC=AD,DC=SANNET,D
$OU.psbase.children | %{$_.displayname} | select-object displayname |
@{name="displayname";expre
Can someone tell me what I am doing wrong? I get no errors, the command just never completes.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or you can do this
Open in new window