September 23rd, 2004, 12:04 AM
Script:Find what service pack a Windows box is running using WMI and ADS
I wrote this script awhile back because I wanted to find out what service packs my Windows boxes at work were running without going to see them, that way I knew which ones to go and install the new service pack on. With XP SP2 out now some of you may find this script useful. Just copy and paste the below into a .vbs file and edit the third line to reflect where in ADS (Active Directory System) you computer accounts would be. Since the script pulls itsí data from ADS itsí results are only as good as how clean you keep your tree (example: Machine accounts for machines that no longer exist). It puts the results in a CSV file for you to look at, and lists info like Machine name, OS and Service Pack. Enjoy, hope it helps someone.
'Adrian's (Irongeek's) Script To Find Service Pack Number using ADS.
'Edit the line below for your network/context
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
Set fs = CreateObject("Scripting.FileSystemObject")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select name, operatingSystem, operatingSystemVersion, operatingSystemServicePack from '" + MyLDAP + "' " _
& "where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
Set f = fs.OpenTextFile("SPinfo.csv", 2,1)
Do Until objRecordSet.EOF
'for each x in objRecordSet.Fields
'msgbox x.name & x.value
Ltxt= objRecordSet.Fields("Name").Value & ", "
Ltxt= Ltxt & objRecordSet.Fields("operatingSystem").Value & ", "
Ltxt= Ltxt & objRecordSet.Fields("operatingSystemVersion").Value & ", "
Ltxt= Ltxt & objRecordSet.Fields("operatingSystemServicePack").Value & vbcrlf
msgbox "Done, look in SPinfo.csv"
September 23rd, 2004, 12:14 AM
Nice, this could save a lot of man hours by not having to sit at every machine especially if your network is large with hundreds of machines.
There wasn\'t any paper used here, but millions of electrons were terribly inconvenienced