Solved

Powershell script to retrieve display name of objects in an AD container

Posted on 2008-10-02
6
1,209 Views
Last Modified: 2012-08-14
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
Comment
Question by:CLSolorzano
  • 4
6 Comments
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22627329
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
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22627414
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
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22627424
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
 

Author Comment

by:CLSolorzano
ID: 22628578
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
 
LVL 18

Accepted Solution

by:
BSonPosh earned 250 total points
ID: 22629139
you never closed the quoted. Also you do not need to do the select either
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This very simple solution applies to a narrow cross-section of the "needs to close" variety. In this case, the full message in Event Viewer was in applog, Event ID 1000: Faulting application iexplore.exe, version 8.0.6001.18702, faulting module …
Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now