Results 1 to 3 of 3

Thread: [RESOLVED] VBScript string truncation?

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    2

    Resolved [RESOLVED] VBScript string truncation?

    Hello,

    I am having some trouble with a VBScript I am trying to write. So far what I have does what it is suppose to do. A fair bit of it is from the Microsoft Scripting guys.

    It checks my Domain for all Windows 2003 servers and queries each server as to what windows updates have been applied. It writes all these to a CSV file. What I would like to do is specify a date and have it either only output the updates from that date or all updates since that date. The current script writes the date field from an object called objEntry.Date

    the date format it outputs is
    Code:
    6/17/2008 1:25PM
    I though maybe I could set the script to ignore anything but the correct date but I am not sure how seperate the text becuase I wont know the very minute an update was installed.

    Code:
    ' Notify user the script has been started
    Wscript.Echo "Click OK to begin Installed Update Check "
    
    'create the filename unique for today's date
    thisDay = day(date())
    thisMonth = Month(date())
    thisYear = year(date())
    thisFileName = "updatelst " & thisYear & "-" & thisMonth & "-" & thisDay
    PathName = outputUNCPath & thisFileName & ".txt"
    Set objFS = CreateObject("Scripting.FileSystemObject")
    Set objNewFile = objFS.CreateTextFile(thisFilename & ".csv")
    objNewFile.WriteLine "Installed Updates"
    objNewFile.WriteLine " "
    objNewFile.WriteLine " "
    
    On Error Resume Next
    
    
    ' Define search scope constant
    Const ADS_SCOPE_SUBTREE = 2
    
    ' Define count variables
    intSrvCount = 0
    
    ' ADSI Connection properties
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Provider = ("ADsDSOObject")
    objConnection.Open "Active Directory Provider"
    objCommand.ActiveConnection = objConnection
    
    ' Set buffer size for performance
    objCommand.Properties("Page Size") = 1000 
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE  
    
    ' SQL Query searching for computers meeting specified OS requirements (Windows 2003)
    ' Specify the domain name for connection
    objCommand.CommandText = _ 
        "SELECT Name, operatingSystemVersion FROM " _   
            & "'LDAP://DC=domain,DC=com'" _ 
                & " WHERE objectClass='computer' AND " _
                    &"operatingSystemVersion = '5.2 (3790)'" 
    Set objRecordSet = objCommand.Execute 
    objRecordSet.MoveFirst 
    
    ' Loop process until all database records that meet criteria have been read (End of File)
    Do Until objRecordSet.EOF 
    ' Assign the variable strComputer the name of the windows 2003 server each pass of the loop
        strComputer = objRecordSet.Fields("Name").Value 
        intSrvCount = intSrvCount + 1
    
    
    Set objSession = CreateObject("Microsoft.Update.Session", strComputer)
    Set objSearcher = objSession.CreateUpdateSearcher
    intHistoryCount = objSearcher.GetTotalHistoryCount
    
    Set colHistory = objSearcher.QueryHistory(1, intHistoryCount)
    
    objNewFile.WriteLine "Server Number: " & "," & intSrvCount
    objNewFile.WriteLine "Server Name: " & "," & strComputer
    
    For Each objEntry in colHistory
        objNewFile.WriteLine "Operation: " & objEntry.Operation
        objNewFile.WriteLine "Result code: " & objEntry.ResultCode
        objNewFile.WriteLine "Exception: " & objEntry.Exception
        objNewFile.WriteLine "Date: " & objEntry.Date
        objNewFile.WriteLine "Title: " & objEntry.Title
        objNewFile.WriteLine "Description: " & objEntry.Description
        objNewFile.WriteLine "Unmapped exception: " & objEntry.UnmappedException
        objNewFile.WriteLine "Client application ID: " & objEntry.ClientApplicationID
        objNewFile.WriteLine "Server selection: " & objEntry.ServerSelection
        objNewFile.WriteLine "Service ID: " & objEntry.ServiceID
        i = 1
        For Each strStep in objEntry.UninstallationSteps
            objNewFile.WriteLine i & " -- " & strStep
            i = i + 1
        Next
        objNewFile.WriteLine "Uninstallation notes: " & objEntry.UninstallationNotes
        objNewFile.WriteLine "Support URL: " & objEntry.SupportURL
        objNewFile.WriteLine
    Next
    	objRecordSet.MoveNext
    Loop
    
    
    objNewFile.Close
    
    ' Notify user the script has completed
    Wscript.Echo "Installed Update Check Completed press OK to continue"
    Thanks for any assistance.

    Carl

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: VBScript string truncation?

    You could use the format function to strip out the time and then compare the dates.

    Code:
    For Each objEntry in colHistory
        If Format(objEntry.Date, "M/D/YYYY") = "6/17/2008" Then
            objNewFile.WriteLine "Operation: " & objEntry.Operation
            objNewFile.WriteLine "Result code: " & objEntry.ResultCode
            objNewFile.WriteLine "Exception: " & objEntry.Exception
            objNewFile.WriteLine "Date: " & objEntry.Date
            objNewFile.WriteLine "Title: " & objEntry.Title
            objNewFile.WriteLine "Description: " & objEntry.Description
            objNewFile.WriteLine "Unmapped exception: " & objEntry.UnmappedException
            objNewFile.WriteLine "Client application ID: " & objEntry.ClientApplicationID
            objNewFile.WriteLine "Server selection: " & objEntry.ServerSelection
            objNewFile.WriteLine "Service ID: " & objEntry.ServiceID
            i = 1
            For Each strStep in objEntry.UninstallationSteps
                objNewFile.WriteLine i & " -- " & strStep
                i = i + 1
            Next
            objNewFile.WriteLine "Uninstallation notes: " & objEntry.UninstallationNotes
            objNewFile.WriteLine "Support URL: " & objEntry.SupportURL
            objNewFile.WriteLine
        End If
    Next

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    2

    Re: VBScript string truncation?

    Thanks Mark that sent me in the right direction this is what I used (I collect the value for the variable d1 from the user and save the formated date as d2)

    Code:
    ' Loop process until all database records that meet criteria have been read (End of File)
    Do Until objRecordSet.EOF 
    ' Assign the variable strComputer the name of the windows 2003 server each pass of the loop
        strComputer = objRecordSet.Fields("Name").Value 
        intSrvCount = intSrvCount + 1
    
    
    Set objSession = CreateObject("Microsoft.Update.Session", strComputer)
    Set objSearcher = objSession.CreateUpdateSearcher
    intHistoryCount = objSearcher.GetTotalHistoryCount
    
    Set colHistory = objSearcher.QueryHistory(1, intHistoryCount)
    
    objNewFile.WriteLine "Server Number: " & "," & intSrvCount
    objNewFile.WriteLine "Server Name: " & "," & strComputer
    
    For Each objEntry in colHistory
    
      d3 = FormatDateTime(objEntry.Date,2)
    
      If  d3 = d2 Then    objNewFile.WriteLine "Operation: " & objEntry.Operation
        objNewFile.WriteLine "Result code: " & objEntry.ResultCode
        objNewFile.WriteLine "Exception: " & objEntry.Exception
        objNewFile.WriteLine "Date: " & objEntry.Date
        objNewFile.WriteLine "Title: " & objEntry.Title
        objNewFile.WriteLine "Description: " & objEntry.Description
        objNewFile.WriteLine "Unmapped exception: " & objEntry.UnmappedException
        objNewFile.WriteLine "Client application ID: " & objEntry.ClientApplicationID
        objNewFile.WriteLine "Server selection: " & objEntry.ServerSelection
        objNewFile.WriteLine "Service ID: " & objEntry.ServiceID
        i = 1
        For Each strStep in objEntry.UninstallationSteps
            objNewFile.WriteLine i & " -- " & strStep
            i = i + 1
        Next
        objNewFile.WriteLine "Uninstallation notes: " & objEntry.UninstallationNotes
        objNewFile.WriteLine "Support URL: " & objEntry.SupportURL
        objNewFile.WriteLine
      End If
    Next
    	objRecordSet.MoveNext
    Loop
    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width