-
September 23rd, 2004, 12:04 AM
#1
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.
Code:
'Adrian's (Irongeek's) Script To Find Service Pack Number using ADS.
'Edit the line below for your network/context
MyLDAP="LDAP://ou=LIBG-Library General,ou=Workstations,ou=SE,dc=ads,dc=ig,dc=com"
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
objRecordSet.MoveFirst
Set f = fs.OpenTextFile("SPinfo.csv", 2,1)
Do Until objRecordSet.EOF
'for each x in objRecordSet.Fields
'msgbox x.name & x.value
'next
Ltxt= objRecordSet.Fields("Name").Value & ", "
Ltxt= Ltxt & objRecordSet.Fields("operatingSystem").Value & ", "
Ltxt= Ltxt & objRecordSet.Fields("operatingSystemVersion").Value & ", "
Ltxt= Ltxt & objRecordSet.Fields("operatingSystemServicePack").Value & vbcrlf
f.write Ltxt
objRecordSet.MoveNext
Loop
msgbox "Done, look in SPinfo.csv"
f.close
-
September 23rd, 2004, 12:14 AM
#2
Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|