Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-10-02
6
Medium Priority
?
1,224 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 1000 total points
ID: 22629139
you never closed the quoted. Also you do not need to do the select either
0

Featured Post

Technology Partners: 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

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

927 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