• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1226
  • Last Modified:

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?
0
CLSolorzano
Asked:
CLSolorzano
  • 4
1 Solution
 
BSonPoshCommented:
the simplest way is to install the free Quest cmdlets from www.quest.com/powershell

or you can do this


$OU = [ADSI]"LDAP://<container path>"
$OU.psbase.children | %{$_.displayname}

Open in new window

0
 
BSonPoshCommented:
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]}

Open in new window

0
 
BSonPoshCommented:
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
0
 
CLSolorzanoAuthor Commented:
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,DC=GOV
$OU.psbase.children | %{$_.displayname} | select-object displayname |
@{name="displayname";expression={$_.Identity.ToString().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.


0
 
BSonPoshCommented:
you never closed the quoted. Also you do not need to do the select either
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now