Announcement

Collapse
No announcement yet.

Help Modifying Script To Retrieve Last Windows Update Date and Time From Computers.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help Modifying Script To Retrieve Last Windows Update Date and Time From Computers.

    Hi Everyone,

    I got this VBS code from this link below.

    http://community.spiceworks.com/how_...-date-and-time

    Can this script be modify to output the results to a CSV or Text file?

    Currently the results shows in a dialog box.

    Thanks!


    Code:
    'Script pulls last Windows update info from registry of all computers specified in computers text file and echos on screen
    
    On Error Resume Next
    
    Set objGetComputerList = CreateObject("Scripting.FileSystemObject") 
    Set fsoReadComputerList = objGetComputerList.OpenTextFile("computers.txt", 1, TristateFalse) 
    aryServers = Split(fsoReadComputerList.ReadAll, vbCrLf) 
    fsoReadComputerList.Close 
    
    For Each strComputer In aryServers
    
    Const HKEY_LOCAL_COMPUTER = &H80000002
    
    strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install" 
    strEntryName = "LastSuccessTime" 
    Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv") 
    objReg.GetStringValue HKEY_LOCAL_COMPUTER, strKeyPath, strEntryName, strValue 
    Wscript.Echo(strComputer & " " & strValue)
    
    Next

  • #2
    Re: Help Modifying Script To Retrieve Last Windows Update Date and Time From Computer

    Take out the wscript.echo and try this

    Code:
    Const ForAppending = 8
    
    If objGetComputerList.FileExists("c:\update.txt") Then
    		Set objTextFile = objGetComputerList.OpenTextFile("c:\update.txt", ForAppending, True)
    		objTextFile.WriteLine(strComputer & " " & strValue)
    		objTextFile.Close
    	Else
    		objGetComputerList.CreateTextFile("c:\update.txt")
    		Set objTextFile = objGetComputerList.OpenTextFile("c:\update.txt", ForAppending, True)
    		objTextFile.WriteLine(strComputer & " " & strValue)
    		objTextFile.Close
    	End If
    That should check if the file exists and if it does open it for appending and write your values. If it doesn't exist it will then create it and open and write your values.

    There is probably a much quicker and easier way to do it and Rems is probably the man to assist.

    Comment


    • #3
      Re: Help Modifying Script To Retrieve Last Windows Update Date and Time From Computer

      Thank you so much for replying wullieb1.

      I added your code to my existing script. Nothing happens after I run it.

      Please look at the script below. Am I doing something wrong?


      Code:
      'Script pulls last Windows update info from registry of all computers specified in computers text file and echos on screen
      
      On Error Resume Next
      
      Set objGetComputerList = CreateObject("Scripting.FileSystemObject") 
      Set fsoReadComputerList = objGetComputerList.OpenTextFile("update.txt", 1, TristateFalse) 
      aryServers = Split(fsoReadComputerList.ReadAll, vbCrLf) 
      fsoReadComputerList.Close 
      
      For Each strComputer In aryServers
      
      Const HKEY_LOCAL_COMPUTER = &H80000002
      
      strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install" 
      strEntryName = "LastSuccessTime" 
      Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
      strComputer & "\root\default:StdRegProv") 
      objReg.GetStringValue HKEY_LOCAL_COMPUTER, strKeyPath, strEntryName, strValue 
      
      Const ForAppending = 8
      
      If objGetComputerList.FileExists("c:\update.txt") Then
      		Set objTextFile = objGetComputerList.OpenTextFile("c:\update.txt", ForAppending, True)
      		objTextFile.WriteLine(strComputer & " " & strValue)
      		objTextFile.Close
      	Else
      		objGetComputerList.CreateTextFile("c:\update.txt")
      		Set objTextFile = objGetComputerList.OpenTextFile("c:\update.txt", ForAppending, True)
      		objTextFile.WriteLine(strComputer & " " & strValue)
      		objTextFile.Close
      	End If
      
      Next

      Comment


      • #4
        Re: Help Modifying Script To Retrieve Last Windows Update Date and Time From Computer

        For testing purpose remove the line: On Error Resume Next

        And the two Const variables below should be defined before the For-Next loop, and not within the loop.
        Code:
        Const HKEY_LOCAL_COMPUTER = &H80000002
        Code:
        Const ForAppending = 8
        _
        Code:
        ' Script pulls last Windows update info from registry of
        ' all computers specified in computers text file and echos on screen
        
        Const HKEY_LOCAL_COMPUTER = &H80000002
        Const ForAppending  = 8
        
        rem On Error Resume Next
        
        strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\" _
            & "Auto Update\Results\Install" 
        strEntryName = "LastSuccessTime" 
        
        Set objGetComputerList = CreateObject("Scripting.FileSystemObject")
        
        Set fsoReadComputerList = objGetComputerList.OpenTextFile("computers.txt", 1) 
        aryServers = Split(fsoReadComputerList.ReadAll, vbCrLf) 
        fsoReadComputerList.Close 
        
        Set objTextFile = objGetComputerList.OpenTextFile("c:\update.txt", _
           ForAppending, True)
        		
        For Each strComputer In aryServers
        
           Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
             strComputer & "\root\default:StdRegProv") 
           objReg.GetStringValue HKEY_LOCAL_COMPUTER, strKeyPath, _
             strEntryName, strValue 
           objTextFile.WriteLine(strComputer & " " & strValue)
        
        Next
        objTextFile.Close
        
        wscript.quit

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: Help Modifying Script To Retrieve Last Windows Update Date and Time From Computer

          Originally posted by Rems View Post
          For testing purpose remove the line: On Error Resume Next

          And the two Const variables below should be defined before the For-Next loop, and not within the loop.
          Code:
          Const HKEY_LOCAL_COMPUTER = &H80000002
          Code:
          Const ForAppending = 8
          _
          Code:
          ' Script pulls last Windows update info from registry of
          ' all computers specified in computers text file and echos on screen
          
          Const HKEY_LOCAL_COMPUTER = &H80000002
          Const ForAppending  = 8
          
          rem On Error Resume Next
          
          strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\" _
              & "Auto Update\Results\Install" 
          strEntryName = "LastSuccessTime" 
          
          Set objGetComputerList = CreateObject("Scripting.FileSystemObject")
          
          Set fsoReadComputerList = objGetComputerList.OpenTextFile("computers.txt", 1) 
          aryServers = Split(fsoReadComputerList.ReadAll, vbCrLf) 
          fsoReadComputerList.Close 
          
          Set objTextFile = objGetComputerList.OpenTextFile("c:\update.txt", _
             ForAppending, True)
          		
          For Each strComputer In aryServers
          
             Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
               strComputer & "\root\default:StdRegProv") 
             objReg.GetStringValue HKEY_LOCAL_COMPUTER, strKeyPath, _
               strEntryName, strValue 
             objTextFile.WriteLine(strComputer & " " & strValue)
          
          Next
          objTextFile.Close
          
          wscript.quit

          Thank you so much for working on this.

          The results did not complete though. It seems to stop if it reaches a computer that is shutdown.

          My computer list shows way over 100 computers and only less than 5 showed up on the results file. I think the script stops if it can't reach a particular computer.

          Can the script be modify to move on to the next computer if a computer is not reachable?

          Comment


          • #6
            Re: Help Modifying Script To Retrieve Last Windows Update Date and Time From Computer

            Originally posted by Shazam View Post
            Thank you so much for working on this.

            The results did not complete though. It seems to stop if it reaches a computer that is shutdown.

            My computer list shows way over 100 computers and only less than 5 showed up on the results file. I think the script stops if it can't reach a particular computer.

            Can the script be modify to move on to the next computer if a computer is not reachable?
            Thanks for catching that Rems. I actually meant to say that. Doh!!!

            As for the new request then you will need to try and ping each system first and if you get a response then proceed if not then skip it.

            I do have one somewhere but I can't find it at this time. Please check on Google somewhere as that will be where I got it

            Comment


            • #7
              Re: Help Modifying Script To Retrieve Last Windows Update Date and Time From Computer

              Ok. I got it to capture all the computers. Leaving the...

              Code:
              On Error Resume Next
              in the code.


              One more thing...

              Can the code be modified to space out the computer names and the date and time? Because when I try to import it in an excel file it's all in one column. If it was more space out, then I can use the delimiter in excel to import it in properly.

              Is this possible?

              Comment


              • #8
                Re: Help Modifying Script To Retrieve Last Windows Update Date and Time From Computer

                Ok I was able to get it resolved. It was actually quite simple.

                I added more spaces between the &" "&.

                Code:
                objTextFile.WriteLine(strComputer & "               " & strValue)
                Thanks everyone for all your help. I really do appreciate it.

                And a special thanks to you Rems. You have helped me in the past before.


                Here is the code I ended up using.


                Code:
                Const HKEY_LOCAL_COMPUTER = &H80000002
                Const ForAppending  = 8
                
                On Error Resume Next
                
                strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\" _
                    & "Auto Update\Results\Install" 
                strEntryName = "LastSuccessTime" 
                
                Set objGetComputerList = CreateObject("Scripting.FileSystemObject")
                
                Set fsoReadComputerList = objGetComputerList.OpenTextFile("C:\FolderLocation\computers.txt", 1) 
                aryServers = Split(fsoReadComputerList.ReadAll, vbCrLf) 
                fsoReadComputerList.Close 
                
                Set objTextFile = objGetComputerList.OpenTextFile("C:\FolderLocation\update.txt", _
                   ForAppending, True)
                		
                For Each strComputer In aryServers
                
                   Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
                     strComputer & "\root\default:StdRegProv") 
                   objReg.GetStringValue HKEY_LOCAL_COMPUTER, strKeyPath, _
                     strEntryName, strValue 
                   objTextFile.WriteLine(strComputer & "               " & strValue)
                
                Next
                objTextFile.Close
                
                wscript.quit

                Comment

                Working...
                X