Video Screencast Help
Protect Your POS Environment Against Retail Data Breaches. Learn More.

Machine last Reboot Time

Created: 09 May 2012 • Updated: 10 May 2012 | 4 comments
snm1502's picture
This issue has been solved. See solution.

Hi,

We are trying to fetch Machine reboot time data from WMI using Custom Inventory. However, getting an error (attached for reference). When tried the script separately it works fine, however, its not populating the data in table coz of the attached error.

Have also tried using the datatype for Data Class as Date, Int and String still same error.

 

'***************************************************
'**********************************************************************
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
 
For Each objOS in colOperatingSystems
    dtmBootup = objOS.LastBootUpTime
    dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
    'dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now)
    Wscript.Echo dtmLastBootupTime
Next
 
Function WMIDateStringToDate(dtmBootup)
    WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
        Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
            & " " & Mid (dtmBootup, 9, 2) & ":" & _
                Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2))
End Function
 
 
'***************************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
 
'**************Check GUID for the custom dataclass --> next line ("Paste guid here")***************
 
set objDCInstance = nse.AddDataClass ("{c31c0071-3d8a-4eda-9be0-c44ab570c0df}")
 
dim objDataClass
set objDataClass = nse.AddDataBlock (objDCInstance)
 
 
'*********Add a new row**********
 
dim objDataRow
set objDataRow = objDataClass.AddRow
 
'*************Set columns***********
 
objDataRow.SetField 0,dtmLastBootupTime
nse.SendQueued
 

Any help / guidance on this would be great...

Thanks in advance.

Comments 4 CommentsJump to latest comment

Mistral's picture

Forgot to attach the error, or i just can't find it?

 

BTW:

[Inv_OS_Operating_System].[Last Boot Up Time]?

snm1502's picture

Thanks for the Reply, Mistral and Apologies for attachment... PFA is an error pop up.

 

Also, we have tried [Inv_OS_Operating_System].[Last Boot Up Time] however, it is not returning the exact details as expected. Hence, we thought of moving on with Custom Inventory to pull the details...

Error.JPG
Mistral's picture

change

objDataRow.SetField 0,dtmLastBootupTime

to

objDataRow.SetField 0,CStr(dtmLastBootupTime)

you need a string.

 

Last Boot Up from Inventory will show correct data (as it uses the same information from WMI) when you run an inventory policy/task before (with checked "Hardware and operating system - CPU, hard drives, memory, firmware, users and groups, etc.").

To be exact you only need (in "Advanced"):

Inventory data classes -> Operating System -> Common -> Operating System

No reason to create a custom inventory policy/task for this.

 

SOLUTION
snm1502's picture

Thanks for the help, Mistral....

 

Script change worked... :)

 

Will work on Inventory to which I agree, yes there is no need to running an custom inventory...

 

Thanks again...