VBScript: Use an LDAP Query to Find All Windows Servers on a Domain

Damn, the ADsDSOObject rocks! This script, which weighs in at less than 20 lines, finds all machines running any form of Windows Server on a given domain. Note that this script isn't useful in finding domain controllers, but rather any machine running Windows Server.

 1'*************************************************************************
 2' This script created by Chrissy LeMaire ([email protected])
 3' Website: https://netnerds.net/
 4'
 5' This script finds all machines running Windows Server (NT, 2000, 2003) in AD
 6'
 7' Msgbox output provides server name and OS version.
 8'
 9' NO WARRANTIES, USE THIS AT YOUR OWN RISK, etc.
10'*************************************************************************
11
12Set objAdRootDSE = GetObject("LDAP://RootDSE")
13Set objRS = CreateObject("adodb.recordset")
14
15varConfigNC = objAdRootDSE.Get("defaultNamingContext")
16strConnstring = "Provider=ADsDSOObject"
17strWQL = "SELECT * FROM 'LDAP://" & varConfigNC & "' WHERE objectCategory= 'Computer' and OperatingSystem = 'Windows*Server*'"
18objRS.Open strWQL, strConnstring
19
20Do Until objRS.EOF
21    Set objServer = GetObject(objRS.Fields.Item(0))
22    strServerName = objServer.CN
23    strOperatingSystem = objServer.OperatingSystem
24    MsgBox strServerName & " is running " & strOperatingSystem
25    objRS.MoveNext
26    Set objServer = Nothing
27Loop
28objRS.Close
29
30Set objRS = Nothing
31Set objAdRootDSE = Nothing

Also, I found this nice reference of Command One Liners while searching the web. Totally handy!