About these ads

List all Computers in a Domain the quick way!

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

Here is how I’ve done

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

oConn.open "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!"
About these ads

One Response to List all Computers in a Domain the quick way!

  1. Pingback: Quick Tip : List the IIS Versions of your Webserver « Raymund Macaalay's Dev Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 197 other followers

%d bloggers like this: