Blade ZipKit - How to update a date property with vbScript through NSH

Version 2
    Share:|

    Blade ZipKit Package Info

    Name: How to update a date property with vbScript through NSH

    Type: NSH Script Job (Type 2)

    BSA Compatible Version: NA

    Version: 1.0

    More Info:

    Created by: Joe Haley

    Tested version on: NA

    Tested against host running: NA


     

    The example below will allow you to update a date property called "LAST_PATCH_DATE_TIME" with the last successful Windows Patch Date.  This is a type 2 NSH script.

     

     

     

    #!/bin/nsh

     

    FULL_PATH_THIS_FILE="$0"

    THIS_FILE=`basename "${FULL_PATH_THIS_FILE}"`

     

    # Find location of embedded script

    LENGTH_OF_MAIN_SCRIPT=`cat "$FULL_PATH_THIS_FILE" | grep -n '### END OF MAIN SCRIPT ###' | grep -v grep | cut -d ':' -f1`

     

    # Increment this by one to move past the line identifier

    LENGTH_OF_MAIN_SCRIPT=`expr $LENGTH_OF_MAIN_SCRIPT + 1`

     

    # Extract Script

    tail +$LENGTH_OF_MAIN_SCRIPT "$FULL_PATH_THIS_FILE" > "/tmp/$$"

     

    # Loop thru target servers

    for target in ${@}

    do

     

    # Copy embedded script to target server

    cp /tmp/$$ //${target}/tmp/$$.vbs

    # Return the last successful patch date by executing the vbscript commands below

    #nexec -i -l ${target} cmd /c "cscript c:\\tmp\\$$.vbs"

    last_patch_date_results=`nexec -i -l ${target} cmd /c "cscript //Nologo c:/tmp/$$.vbs"`

     

    # Update the BSA Server property

    #last_patch_date_results="2001/01/01 09:15:12"

    blcli_execute Server setPropertyValueByName "$target" LAST_PATCH_DATE_TIME "$last_patch_date_results"

     

    # Remove the temp script file from the target server

    rm -f //${target}/tmp/$$.vbs

    done

     

    # Remove temp script file from app server

    rm -f /tmp/$$

    exit 0

     

    ### END OF MAIN SCRIPT ###

    On Error Resume Next

     

    strComputer = "."

    Set objSession = CreateObject("Microsoft.Update.Session")

    Set objSearcher = objSession.CreateUpdateSearcher

    intHistoryCount = objSearcher.GetTotalHistoryCount

    'Set colHistory = objSearcher.QueryHistory(1, 1)

    Set colHistory = objSearcher.QueryHistory(1, intHistoryCount)

    ' Loop thru all Windows Updates and exit when find most recent successful update

    For Each objEntry in colHistory

        If objEntry.ResultCode = "2" Then

           'Wscript.Echo objEntry.ResultCode

             

           convertPatchDate = ConvertDateForBSA(CDate(objEntry.Date))

           Wscript.Echo convertPatchDate

       

           WScript.Quit

        End If

    Next

     

     

     

    Function ConvertDateForBSA(patchDate)

      convertPatchDate = year(patchDate) & "/" & _

                right("0" & month(patchDate), 2) &  "/" & _

                right("0" & day(patchDate), 2) & " " & _

                right("0" & hour(patchDate), 2) &  ":" & _

                right("0" & minute(patchDate), 2) &  ":" & _

                right("0" & second(patchDate), 2)

       ConvertDateForBSA = convertPatchDate 

    End Function