Solved

Dump computer accounts into a text file

Posted on 2008-10-09
7
406 Views
Last Modified: 2012-05-05
Hi Experts.  I know this is easy but I have tried to do it on my own and haven't been successful.  I suck at scripting so please be patient.

I need to dump the computer accounts in my domain to a text file.  I am not sure how to write or run this.  Thank you for your help.
0
Comment
Question by:samiam41
[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
  • 5
7 Comments
 
LVL 3

Accepted Solution

by:
gcauthon earned 500 total points
ID: 22682042
Install an ldapsearch utility if you don't already have one.  You can get a free one from cygwin.com.  Then you can simply query AD using ldapsearch like so:

ldapsearch -H ldap://server -D username -x -w password -b ou=Workstations,dc=mycompany,dc=com "(objectclass=computer)" "cn" > computers.txt

Obviously, you'll have to look up some of those query parameters from your own AD server.  Configurations vary company to company.
0
 
LVL 9

Author Comment

by:samiam41
ID: 22682057
Thanks!  That gives me some place to start from.  I will let you know how it goes.
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 22682095
Or, on a DC, type:

DSQUERY COMPUTER -O RDN

Of course, that won't just get the workstations, that will get every computer in the domain.

However, you can still use DSQUERY to get computers in a specific OU if you want to.

More info on DSQUERY
http://technet.microsoft.com/en-us/library/cc732952.aspx
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 9

Author Comment

by:samiam41
ID: 22685986
leew > I don't have access to the DC from where I am.  

I am still working on this and will update later this morning.
0
 
LVL 9

Author Comment

by:samiam41
ID: 22689180
On the dsquery, maybe I am missing something (wouldn't doubt it) but this looks like it will provide OU's in the domain.

dsquery ou [{<StartNode> | forestroot | domainroot}] [-o {dn | rdn}][-scope {subtree | onelevel | base}][-name <Name] [-desc <Description>] [{-s <Server> | -d <Domain>}] [-u <UserName>] [-p {<Password> | *}] [-q] [-r] [-gc] [-limit <NumberOfObjects>] [{-uc | -uco | -uci}]
0
 
LVL 9

Author Comment

by:samiam41
ID: 22689467
I found my old post that had the script I needed.


Dim counter
'-----------------------------------------------
'Create New excel workbook
'-----------------------------------------------
Set Excel = CreateObject("Excel.Application")
Excel.Visible = True
Excel.Workbooks.Add
counter =1 'init to first cell
 
 
DoRecursive("OU=WBC,DC=corp")
 
Function DoRecursive(strObjectDN)
  'Retrieve a list of OU's for this level
 Set oneLevelOU= GetObject("LDAP://" & strObjectDN)
 
 For Each OU in oneLevelOU
'-----------------------------------------------
'if ou is computers then add to
'-----------------------------------------------
 If InStr(1,ou.name,"Computers")>0 Then 
Set objOU = GetObject("LDAP://" &  OU.name & "," & strObjectDN)
objOU.Filter = Array("Computer")
For Each objComputer in objOU
       Excel.Cells(counter,1).Value = objComputer.CN
           Excel.Cells(counter,2).Value = "LDAP://" &  OU.name & "," & strObjectDN
       counter =counter +1
Next
 End If
    DoRecursive( OU.name & "," & strObjectDN)
 Next
End Function

Open in new window

0
 
LVL 9

Author Closing Comment

by:samiam41
ID: 31504808
Thanks for your help.  I never used your suggestion put it gave me an additional resource to try and I will accept your answer.  Take care!

-Aaron
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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