'********************************************************************************
' NS7 Custinv to return OS install date from the win32_operatingsystem wmi class
'********************************************************************************
'Create instance of Wbem service object, connect to namespace and run wmi query
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'Create instance of DateTime object
Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
'===================================================================================================================
'Create instance of Altiris NSE component
dim nse
set nse = WScript.CreateObject ("Altiris.AeXNSEvent")
' Set the header data of the NSE
' Please don't modify this GUID
nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"
nse.Priority = 1
'Create Inventory data block. Here assumption is that the data class with below guid is already configured on server
dim objDCInstance
set objDCInstance = nse.AddDataClass ("{22c12ff5-4166-4c33-9ab7-f630cb949878}")
dim objDataClass
set objDataClass = nse.AddDataBlock (objDCInstance)
cnt=0
Set objWMIObj = objWMIService.ExecQuery("SELECT * FROM win32_operatingsystem")
For each objInfo in objWMIObj
'Add a new row
dim objDataRow
set objDataRow = objDataClass.AddRow
'Set columns
LastBootUpTime = FormatFileDate(objInfo.LastBootUpTime)
Wscript.echo LastBootUpTime
objDataRow.SetField 0, LastBootUpTime
' objDataRow.SetField 5, FormatFileDate(objInfo.LastBootUpTime)
' WScript.echo "Parsed LastBootUpTime: " & objInfo.LastBootUpTime & " ---> " & ParseWMIDate(objInfo.LastBootUpTime)
' WScript.echo "Object LastBootUpTime: " & objInfo.LastBootUpTime & " ---> " & FormatFileDate(objInfo.LastBootUpTime)
Next
' Send the NSE data to the NS server
nse.SendQueued
' Method 1: Manually parse out date & time in correct order & build CDate object
Function ParseWMIDate(dtmLastBootUpTime)
ParseWMIDate = _
CStr(Mid(dtmLastBootUpTime, 5, 2) &_
"/" &_
Mid(dtmLastBootUpTime, 7, 2) &_
"/" &_
Left(dtmLastBootUpTime, 4) &_
" " &_
Mid (dtmLastBootUpTime, 9, 2) &_
":" &_
Mid(dtmLastBootUpTime, 11, 2) &_
":" &_
Mid(dtmLastBootUpTime, 13, 2))
End Function
' Method 2: Use wbem objects to get wbem-formatted date
Function FormatFileDate (strDate)
objSWbemDateTime.Value = strDate
FormatFileDate = CStr(objSWbemDateTime.GetVarDate(False))
End Function
I didn't write this from scratch. I think that there was another forum posting on Connect that I lifted this from.
I have the custom inventory running daily and at system startup.