Solved

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

Posted on 2008-10-02
6
1,214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need VBA code to change date format of Column A 5 40
A Table within a User Form 24 81
Split on ASP 8 53
INSERT value into first row in 75 workbooks 8 38
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)…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Viewers will learn the different options available in the Backstage view in Excel 2013.
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…

752 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