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.
‘ This script created by Chrissy LeMaire ([email protected])
‘ Website: http://netnerds.net/
‘
‘ This script finds all machines running Windows Server (NT, 2000, 2003) in AD
‘
‘Msgbox output provides server name and OS version.
‘
‘ NO WARRANTIES, USE THIS AT YOUR OWN RISK, etc.
‘*****************************************************************************
Set objAdRootDSE = GetObject(“LDAP://RootDSE”)
Set objRS = CreateObject(“adodb.recordset”)
varConfigNC = objAdRootDSE.Get(“defaultNamingContext”)
strConnstring = “Provider=ADsDSOObject”
strWQL = “SELECT * FROM ‘LDAP://” & varConfigNC & “‘ WHERE objectCategory= ‘Computer’ and OperatingSystem = ‘Windows*Server*'”
objRS.Open strWQL, strConnstring
Do until objRS.eof
Set objServer = GetObject(objRS.Fields.Item(0))
strServerName = objServer.CN
strOperatingSystem = objServer.OperatingSystem
MsgBox strServerName & ” is running ” & strOperatingSystem
objRS.movenext
Set objServer = Nothing
Loop
objRS.close
Set objRS = Nothing
Set objAdRootDSE = Nothing
Also, I found this nice reference of Command One Liners while searching the web. Totally handy!
Recent Comments