'################################################################################ '# warrantyInfo.vbs - Version 2.4 # '# Copyright 2010 Ryan McLean (ryan1_00 _A_T_ hotmail _D_O_T_ com) # '# # '# License: GPL v2 or later # '# # '# Thanks to: # '# Sherry Kissinger for posting the original script (I found it on myitforum) # '# Chris Duszenski for the Updated version of the script that this is based on # '# # '# Notes: # '# You MUST update your sms_def.mof file with the code below if you want # '# to use the WMI for capturing. IT IS DIFFERENT from other versions of # '# this script # '# # '# Disclaimer: # '# This script "works for me", it may break your network, it may cause # '# world war 3. If it does, or even if it doesn't work at all, I am not # '# not liable, there is no warranty implied or otherwise. # '# By using the script you agree that anything it does or doesn't do is your # '# own fault and not mine. # '# # '# If in doubt read the code, all improvements, suggestions and fixs welcome # '# # '# # '################################################################################ ' Removes file once read '#################################################################################### 'Add the Following to \inboxes\clifiles.src\hinv\sms_def.mof '// <:[-<>>>>>>>>>>>>>>>>>>>>>>Begin>>-Warranty Info-<=]:> '#pragma namespace ("\\\\.\\root\\cimv2\\SMS") '[ SMS_Report (TRUE), ' SMS_Group_Name ("Warranty Info"), ' SMS_Class_ID ("CUSTOM|Warranty_Info|3.0") ] 'class Warranty_Info : SMS_Class_Template '{ ' [SMS_Report(TRUE)] string DateScriptRan; ' [SMS_Report(TRUE)] string ServiceTag; ' [SMS_Report(TRUE)] string SystemType; ' [SMS_Report(TRUE)] string ShipDate; ' [SMS_Report(TRUE)] string DellIBU; ' [SMS_Report(TRUE), Key] string Description; ' [SMS_Report(TRUE)] string Provider; ' [SMS_Report(TRUE)] string StartDate; ' [SMS_Report(TRUE)] string EndDate; ' [SMS_Report(TRUE)] uint32 DaysLeft; ' [SMS_Report(TRUE)] string WarrantyExtended; '}; '// <:[-<>>>>>>>>>>>>>>>>>>>>>>End>>-Warranty Info-<=]:> '#################################################################################### On Error Resume Next '############# USER CHANGEABLE CONSTANTS ######## ' Version Number here should match the SMS_DEF.mof file line: ' CUSTOM|Warranty_Info|X.X Const SMSDEFVERSION = "3.0" ' Use the System Temp folder, if false then add path to INFILE Const USE_SYS_TEMP_FLDR = true INFILE = "warrantyInfo.csv" ' Logging Const ENABLE_LOGGING = true Const LOGFILE = "C:\Windows\Logs\SCCM-Dell_Warranty_Info.log" '################################################ '############# CONSTANTS ######################## ' File I/O Const forREADING = 1 Const forWRITING = 2 Const forAPPENDING = 8 'System Locations Const TemporaryFolder = 2 ' WMI Const wbemCimtypeSint16 = 2 Const wbemCimtypeSint32 = 3 Const wbemCimtypeReal32 = 4 Const wbemCimtypeReal64 = 5 Const wbemCimtypeString = 8 Const wbemCimtypeBoolean = 11 Const wbemCimtypeObject = 13 Const wbemCimtypeSint8 = 16 Const wbemCimtypeUint8 = 17 Const wbemCimtypeUint16 = 18 Const wbemCimtypeUint32 = 19 Const wbemCimtypeSint64 = 20 Const wbemCimtypeUint64 = 21 Const wbemCimtypeDateTime = 101 Const wbemCimtypeReference = 102 Const wbemCimtypeChar16 = 103 '################################################ '########################### Determine the Temp Dir to use ########################## IF USE_SYS_TEMP_FLDR = true THEN 'wscript.echo "Setting Temp Dir" Set fso = CreateObject("Scripting.FileSystemObject") Set tfolder = fso.GetSpecialFolder(TemporaryFolder) INFILE = tfolder & "\" & INFILE If ENABLE_LOGGING = true Then strLOG = now & ",Set Folder," & "," & "INFILE = " & INFILE Call writeFile (strLOG, true) End If 'wscript.echo "INFILE = " & INFILE Set fso = Nothing Set tfolder = Nothing END IF '#################################################################################### '############# CALL MAIN ######################## Call Main() '################################################ '############# MAIN() ########################### Sub Main() 'wscript.echo "Main.." Dim csvData ScriptRunDate = Now 'wscript.echo ScriptRunDate If ENABLE_LOGGING = true Then strLOG = now & ",Main," & "," & "Script starting" Call writeFile (strLOG, true) End If 'wscript.echo "Read File" csvData = readFile() 'wscript.echo csvData & vbcrlf arrWarrantyInfo = Split(csvData, ",") If ENABLE_LOGGING = true Then strLOG = now & ",Main," & "," & "Output to WMI" Call writeFile (strLOG, true) End If 'wscript.echo "Delete WMI Warranty Info.." call deleteWMIWarrantyInfo() 'wscript.echo "Create WMI Warranty Info Class.." call CreateWMIWarrantyInfoClass() 'wscript.echo "Populate WMI Warranty Info.." call populateWMIWarrantyInfo(arrWarrantyInfo) 'wscript.echo "Done" If ENABLE_LOGGING = true Then strLOG = now & ",Main," & "," & "Script Finished" Call writeFile (strLOG, true) End If wscript.quit(0) End Sub '################################################ '############# FUNCTIONS AND SUB ROUTINES ####### Function readFile() On Error Resume Next 'wscript.echo "Reading File.." ' Used to read in an HTML page that has been ' copied from the vendor site in order to reduce ' the hits on their site while testing 'wscript.echo "Reading file: " & infile Dim objFSO, objFile, objReadFile Dim strFile Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.GetFile(INFILE) If Err.Number <> 0 Then 'wscript.echo Err.Number & " " & Err.Description If ENABLE_LOGGING = true Then strLOG = now & ",readFile," & Err.Number & "," & Err.Description Call writeFile (strLOG, true) End If wscript.quit(1) End If If objFile.Size > 0 Then Set objReadFile = objFSO.OpenTextFile(INFILE, forREADING) i = 0 strFile = "" Do Until objReadFile.AtEndOfStream If i = 0 Then ' Remove 1st line strLine = objReadFile.Readline i = i + 1 Else strLine = objReadFile.Readline If strLine <> "" Then If strFile <> "" Then strFile = strFile & "," & strLine Else strFile = strLine End If End If End If Loop 'wscript.echo strFile Else If ENABLE_LOGGING = true Then strLOG = now & ",readFile," & "," & "The file is empty." Call writeFile (strLOG, true) End If 'wscript.Echo "The file is empty." wscript.quit(1) End If Set objReadFile = Nothing Set objFile = Nothing objFSO.DeleteFile(INFILE) Set objFSO = Nothing strFile = Replace(strFile, "'","") 'wscript.echo strFile readFile = strFile End Function Sub deleteWMIWarrantyInfo() on error resume next 'wscript.echo "Deleting WMI Warranty Info.." Set oLocation = CreateObject("WbemScripting.SWbemLocator") 'Remove classes Set oServices = oLocation.ConnectServer(, "root\cimv2") Set oNewObject = oServices.Get("Warranty_Info") If Err.Number = -2147217406 Then strLOG = now & ",deleteWMIWarrantyInfo,,WMI Class 'Warranty_Info' does not exist" If ENABLE_LOGGING = true Then Call writeFile (strLOG, true) End If ElseIF Err.Number <> 0 Then strLOG = now & ",deleteWMIWarrantyInfo," & Err.Number & "," & Err.Description If ENABLE_LOGGING = true Then Call writeFile (strLOG, true) End If Else oNewObject.Delete_ If ENABLE_LOGGING = true Then strLOG = now & ",deleteWMIWarrantyInfo," & "," & "Warranty_Info class deleted" Call writeFile (strLOG, true) End If End If Set oLocation = Nothing Set oServices = Nothing End Sub Sub CreateWMIWarrantyInfoClass() 'wscript.echo "Creating WMI Warranty Info Class.." Set oLocation = CreateObject("WbemScripting.SWbemLocator") Set oServices = oLocation.ConnectServer(, "root\cimv2") 'Create data class structure Set oDataObject = oServices.Get oDataObject.Path_.Class = "Warranty_Info" oDataObject.Properties_.add "DateScriptRan", wbemCimtypeString oDataObject.Properties_.add "ServiceTag", wbemCimtypeString oDataObject.Properties_.add "SystemType", wbemCimtypeString oDataObject.Properties_.add "ShipDate", wbemCimtypeString oDataObject.Properties_.add "DellIBU", wbemCimtypeString oDataObject.Properties_.add "Description", wbemCimtypeString oDataObject.Properties_.add "Provider", wbemCimtypeString oDataObject.Properties_.add "StartDate", wbemCimtypeString oDataObject.Properties_.add "EndDate", wbemCimtypeString oDataObject.Properties_.add "DaysLeft", wbemCimtypeUint32 oDataObject.Properties_.add "WarrantyExtended", wbemCimtypeString oDataObject.Properties_("Description").Qualifiers_.add "key", True oDataObject.Put_ Set oLocation = Nothing Set oServices = Nothing Set oDataObject = Nothing End Sub Sub populateWMIWarrantyInfo(data) 'wscript.echo "Populating WMI Warranty Info.." Set oLocation = CreateObject("WbemScripting.SWbemLocator") Set oServices = oLocation.ConnectServer(, "root\cimv2") 'Calc contracts intLoopCount = UBound(data) / 11 'wscript.echo "Total elements: " & UBound(data) & vbcrlf & "Number of Loops: " & intLoopCount 'Populate For i = 1 To intLoopCount 'wscript.echo "DateScriptRan: " & data(0) & vbcrlf & _ '"ServiceTag: " & data(1) & vbcrlf & _ '"SystemType: " & data(2) & vbcrlf & _ '"ShipDate: " & data(3) & vbcrlf & _ '"DellIBU: " & data(4) & vbcrlf & _ '"Description: " & data(6+(12*(i-1))) & vbcrlf & _ '"Provider: " & data(7+(12*(i-1))) & vbcrlf & _ '"StartDate: " & data(9+(12*(i-1))) & vbcrlf & _ '"EndDate: " & data(10+(12*(i-1))) & vbcrlf & _ '"DaysLeft: " & data(11+(12*(i-1))) & vbcrlf & _ '"WarrantyExtended: " & data(5) Set oNewObject = oServices.Get("Warranty_Info").SpawnInstance_ oNewObject.DateScriptRan = data(0) oNewObject.ServiceTag = data(1) oNewObject.SystemType = data(2) oNewObject.ShipDate = data(3) oNewObject.DellIBU = data(4) oNewObject.Description = data(6+(12*(i-1))) oNewObject.Provider = data(7+(12*(i-1))) oNewObject.StartDate = data(9+(12*(i-1))) oNewObject.EndDate = data(10+(12*(i-1))) oNewObject.DaysLeft = data(11+(12*(i-1))) oNewObject.WarrantyExtended = data(5) oNewObject.Put_ Next 'wscript.echo "DONE" Set oLocation = Nothing Set oServices = Nothing Set oNewObject = Nothing End Sub Sub writeFile(data, islog) 'wscript.echo "Writing file" Set myFSO = CreateObject("Scripting.FileSystemObject") If islog = true Then 'wscript.echo "Writing to: " & LOGFILE Set myfile = myFSO.OpenTextFile(LOGFILE, forAPPENDING, True) Else 'wscript.echo "Writing to: " & OUTFILE Set myfile = myFSO.OpenTextFile(OUTFILE, forWRITING, True) End If myfile.WriteLine(data) myfile.Close Set myfile = Nothing Set myFSO = Nothing End Sub '################################################