Click here to Skip to main content
Click here to Skip to main content

List all Computers in a Domain the quick way!

By , 22 Mar 2010
Rate this:
Please Sign up or sign in to vote.

This is in conjunction with my work here where I need to list all websites in a server, now I need to list all servers and what's the quick way of doing it? Again scripting in VBS.

Here is how I’ve done it:

const oFileName ="AllComputers.csv"
set oCmd = createobject("ADODB.Command")
set oConn = createobject("ADODB.Connection")
set oRS = createobject("ADODB.Recordset") "Provider=ADsDSOObject;"
oCmd.ActiveConnection = oConn

set oRoot = GetObject("LDAP://RootDSE")

oCmd.CommandText = "<LDAP://" & oRoot.Get("defaultNamingContext")  
		& ">;(objectCategory=Computer);" & _
          	"name, distinguishedName, operatingsystem, 
		operatingsystemservicepack, operatingsystemversion;subtree"
oCmd.Properties("page size")=1000

set oRS = oCmd.Execute
set oFSO = CreateObject("Scripting.FileSystemObject")
set oCSV = oFSO.CreateTextFile(oFileName)

sQuotations = """"

while oRS.EOF <> true and oRS.BOF <> true
    oCSV.writeline(sQuotations & oRS("name") & sQuotations & "," & _
    sQuotations & oRS("distinguishedName") & sQuotations & "," &  _
    sQuotations & oRS("operatingsystem") & sQuotations & "," & _
    sQuotations & oRS("operatingsystemservicepack") & sQuotations & "," & _
    sQuotations & oRS("operatingsystemversion") & sQuotations)


wscript.echo "Done!"


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Raymund Macaalay
Technical Lead
New Zealand New Zealand
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

GeneralMy vote of 3 Pinmembertonymon98765420-Sep-10 21:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 22 Mar 2010
Article Copyright 2010 by Raymund Macaalay
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid