Client Management Suite

 View Only
  • 1.  Get OS InstalledDate custom inventory vbscript doesn't work

    Posted Jan 25, 2012 06:21 AM

    Hi,

    I would like to create a custom inventory task to collect the date stamp of when the OS was installed on my client machines.

    I followed the instructions on how to create a custom inventory.

    1. I created a new data class called OSInstalledDate, in that data class I created a string that I call InstalledDate.

    2. I created this script:

    'Following is a sample custom inventory sript gathering information about processor of a machine and posting data

    'to NS using Altiris NSE Component
    '===================================================================================================================
    '      On Error Resume Next
     
    'Create instance of Wbem service object and connect to namespace
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set dtmInstallDate = CreateObject("WbemScripting.SWbemDateTime")
    'Fire WMI Query
    Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
     
     
    '===================================================================================================================
     
    '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 ("OSInstalledDate")
     
    dim objDataClass
    set objDataClass = nse.AddDataBlock (objDCInstance)
     
    For Each objOperatingSystem in colOperatingSystems
    dim sInstalledDate
    sInstalledDate = getmydat (objOperatingSystem.InstallDate)
    'Add a new row
    dim objDataRow
    set objDataRow = objDataClass.AddRow
    'Set columns
    'MsgBox "Install Date: " & sInstalledDate
    objDataRow.SetField 0, sInstalledDate
    Next
     
    nse.SendQueued
     
     
    Function getmydat(wmitime)
      dtmInstallDate.Value = wmitime
      getmydat = dtmInstallDate.GetVarDate
    End function

     

    But if I run the script I get this error:

    Script: InstalledDate.vbs
    Line: 40
    Char: 2
    Error: Invalid type for data field
    Code: 80070057
    Source: (null)
     
    Any idea on what I am doing wrong?
     
    Greets Seid,


  • 2.  RE: Get OS InstalledDate custom inventory vbscript doesn't work

    Posted Jan 25, 2012 09:53 AM

    Where you have OSINSTALLEDDATE by add dataclass you should have a guid. Kinda like this

     

     

    '===================================================================================================================
    '      On Error Resume Next
     
    '**** Global Variables************************ 
     
    const HKEY_LOCAL_MACHINE = &H80000002
    const REG_SZ = 1
    const REG_EXPAND_SZ = 2
    const REG_BINARY = 3
    const REG_DWORD = 4
    const REG_MULTI_SZ = 7
     
    strComputer = "."
    Set StdOut = WScript.StdOut
     
    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
    strComputer & "\root\default:StdRegProv")
     
    strKeyPath = "SOFTWARE\MICROSOFT\INTERNET EXPLORER"
    strValueName="version"
     
     
    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
     
    'wscript.echo strValue
    version=strValue
     
    '===================================================================================================================
     
    '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 ("{0944666a-58b0-461c-9d7e-fb8fab322e90}")
     
    dim objDataClass
    set objDataClass = nse.AddDataBlock (objDCInstance)
     
     
    'Add a new row
    dim objDataRow
    set objDataRow = objDataClass.AddRow
    'Set columns
    objDataRow.SetField 0,Version
     
     
    nse.SendQueued
     
     
    Something to remember though is that you need to go settings>all settings > discovery and inventory>Inventory solution> Manage custom data classes and create it there. I tried to do it other ways and it always acted up when my test machine turned in the NSE. When I created it there it worked fine.
     
     
    Also I use this to put the date in a more readable format for my machines because if I used the function you have for date I ran into an issue on machines in other countries that set the date into different formats. It was returning it to my server and giving me a lot of different formats which made it useless for inventory. 
     
     
    Function getmydat(strDate)
     
      getmydat = Left(strDate, 4) & "-" & MID(strdate,5,2) & "-" & MID(strdate,7,2)
           
    End function


  • 3.  RE: Get OS InstalledDate custom inventory vbscript doesn't work
    Best Answer

    Posted Jan 25, 2012 12:02 PM

    This is already gathered by default in the Software inventory.

    SELECT vc.Guid as '_ItemGuid',
    vc.Name,
    oos.[Name],
    oos.[Install Date]
    FROM vComputer vc
    JOIN Inv_OS_Operating_System oos ON oos._ResourceGuid=vc.Guid



  • 4.  RE: Get OS InstalledDate custom inventory vbscript doesn't work

    Posted Jan 26, 2012 03:03 AM

    Thanks for the info mclemson, this is probably the best solution for this problem :-)