Solved

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
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 …

679 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