Solved

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

Posted on 2008-10-02
6
1,210 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

920 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

15 Experts available now in Live!

Get 1:1 Help Now