Hi all!
I have successfully created a custom inventory script that will return the version of a dll (see Script #1). But I would like to create a custom inventory script that I can add and remove several files to for future use. I have a script that a previous colleague created that can search for and find files. I have tried to modify that script (see Script #2), but I never get it to get the file version. I guess it never successfully runs that part of the script.
My scritping skills is limited to copy and paste and what Google can offer, and this is as far as I managed to get ;).
Any ideas?
Script #1 (which works, but only checks one file)
Set objDictionary = CreateObject("Scripting.Dictionary")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Name = 'c:\\windows\\system32\\Gpprefcl.dll'")
For Each objFile in colFiles
FileVer = objFile.Version
Next
'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 ("{24363bf0-ee59-46c9-b0aa-bf9e68229477}")
dim objDataClass
set objDataClass = nse.AddDataBlock (objDCInstance)
'Add a new row
dim objDataRow
set objDataRow = objDataClass.AddRow
'Set columns
objDataRow.SetField 0, FileVer
wscript.echo nse.xml
'nse.SendQueued
Script #2 (what I would like to use, but do not report the file version)
'change the next line to demo=false for production
demo=true
'change the next line and use the GUID of your new inventory data class
CustInvClassGUID = "{29f31b62-801d-48e8-a848-723db0cbb379}"
'Set some variables and constants
On Error Resume Next
Dim FileSystemObject
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("WScript.Shell")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'Class File
Class File
Public Name
Public Found
End Class
'Declare an array that will contain the Files we want to inventory
Dim KeyList(1)
'Loop through the array and create one instance of RegKey for each value in the array.
For i = 0 To UBound(KeyList)
Set KeyList(i) = New File
Next
'Set reg Provider, KeyPath, KeyName and KeyType for each value to inventory
KeyList(0).Name = "c:\\windows\\system32\\Gpprefcl.dll"
'Create Altiris Objects
Set nse = WScript.CreateObject ("Altiris.AeXNSEvent")
nse.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"
nse.Priority = 100
set objDCInstance = nse.AddDataClass (CustInvClassGUID)
set objDataClass = nse.AddDataBlock (objDCInstance)
objDataClass.PartialUpdate = false
'Loop through all keys and get their values
For i = 0 To UBound(KeyList)
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Name = KeyList(i).Name")
For Each objFile in colFiles
KeyList(i).FileVer = objFile.Version
Next
Next
'Loop through all keys and create new DBRow in nse.xml
For i = 0 To UBound(KeyList)
Set objDataRow = objDataClass.AddRow
objDataRow.SetField 0, KeyList(i).Name
objDataRow.SetField 1, KeyList(i).FileVer
objDataRow.SetField 2, Year(Date()) & "-" & Month(Date()) & "-" & Day(Date()) & " " & Hour(Now)& ":" & Minute(Now)
' End If
Next
' If demo, echo output values and nse.xml, else nse.Send
If demo then
wscript.echo nse.xml
else
nse.Send
end if