Script:Find what service pack a Windows box is running using WMI and ADS
Results 1 to 2 of 2

Thread: Script:Find what service pack a Windows box is running using WMI and ADS

  1. #1
    King Tutorial-ankhamun
    Join Date
    Jul 2004

    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
    MyLDAP="LDAP://ou=LIBG-Library General,ou=Workstations,ou=SE,dc=ads,dc=ig,dc=com"
    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.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
    	f.write Ltxt 
    msgbox "Done, look in SPinfo.csv"

  2. #2
    Join Date
    Sep 2004
    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

 Security News


       Security Trends


           Buying Guides