Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.

Custom Inventory - VBScript

Created: 20 Jul 2013 • Updated: 20 Jul 2013 | 2 comments
EugeneDisc's picture

Hi there,

Hope you well and able to assist :)

I have a VBScript collecting data from a text file, it searches for the keyword m_HbaName and should then return the value to the right.

However, there are two entries and it only returns the last one of the two.

____________________________________________________________________________________________

SCRIPT:

------------------------------------------------------------------------------------------------------------------------------------------------------------------

Set oShell = WScript.CreateObject("WSCript.shell") 
 
dim filesys, newfolder, newfolderpath
newfolderpath = "C:\CustInv" 
set filesys=CreateObject("Scripting.FileSystemObject") 
If Not filesys.FolderExists(newfolderpath) Then 
  Set newfolder = filesys.CreateFolder(newfolderpath) 
End If
 
oShell.run "cmd /c type c:\cnaboardmgmt.log >c:\CustInv\wwnoutput.txt", 0, True
 
 
Const ForReading = 1
dim wwn, strkey1
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "m_HbaName"
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\CustInv\wwnoutput.txt", ForReading)
 
 
Do Until objFile.AtEndOfStream
    strSearchString = objFile.ReadLine
    Set colMatches = objRegEx.Execute(strSearchString)  
    If colMatches.Count > 0 Then
        For Each strMatch in colMatches
strkey1 = Mid(strSearchString, 19, 23)       
        Next
    End If
Loop
 
objFile.Close
 
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
 
'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 ("{9778a2d0-8538-484d-b7da-d15b03f66335}")
 
dim objDataClass
set objDataClass = nse.AddDataBlock (objDCInstance)
 
 
'Add a new row
dim objDataRow
set objDataRow = objDataClass.AddRow
 
'Set columns
objDataRow.SetField 0,strkey1
 
 
 
 
nse.SendQueued
______________________________________________________________________________________
 
File i need data from, i highlighted that which i need:
------------------------------------------------------------------------------------------------------------------------------------------------------
Board           : 0
Is Init         : 0
m_DevId         : f10b
m_SubDeviceId   : f126
m_SubVendorId   : 10df
m_drvFeatureList: 557
m_drvInfoVer    : 4
m_drvType       : 3
m_HbaName       : 10:00:00:00:c9:d3:30:78
m_DefaultWWPN   : 00:00:00:00:00:00:00:00
Is IBM          : 0
SLI mode        : 3
PCI Func. #     : 0
VPD Port# (V4)  : 0
VPD SN (SN)     : FC15211031
VPD Model (V2)  : LPe1205-M
 
Board           : 1
Is Init         : 0
m_DevId         : f10b
m_SubDeviceId   : f126
m_SubVendorId   : 10df
m_drvFeatureList: 557
m_drvInfoVer    : 4
m_drvType       : 3
m_HbaName       : 10:00:00:00:c9:d3:30:79
m_DefaultWWPN   : 00:00:00:00:00:00:00:00
Is IBM          : 0
SLI mode        : 3
PCI Func. #     : 1
VPD Port# (V4)  : 1
VPD SN (SN)     : FC15211031
VPD Model (V2)  : LPe1205-M

______________________________________________________________________________________

Result in DB:

------------------------------------------------------------------------------------------------------------------------------------------------------

 

_id        _ResourceGuid                                                    WWN
5          13887A05-A8D8-4DAB-8BBC-1F2591CC94AF        10:00:00:00:c9:d3:30:79
_________________________________________________________________________________________
 
What i need:
------------------------------------------------------------------------------------------------------------------------------------------------------------
_ResourceGuid                                                WWN1                                    WWN2
13887A05-A8D8-4DAB-8BBC-1F2591CC94AF   10:00:00:00:c9:d3:30:79           10:00:00:00:c9:d3:30:78
_________________________________________________________________________________________
 
 
Hope this all makes sense and that someone can point me in the right direction.
 
Thank you all in advance.
Eugene

 

Operating Systems:

Comments 2 CommentsJump to latest comment

Falquian's picture

Hi Eugene:

I see you have the following for-next loop

        For Each strMatch in colMatches
              strkey1 = Mid(strSearchString, 19, 23)       
        Next
In this loop you are only saving the value for the last entry in the text file.
 
According to the "What I need" section of your text :P it seems that you'll have a dataclass with three fields:
_ResourceGuid
WWN1 and
WWN2
 
This has one big disadvantage (from my point of view): You are limiting the maximun number of occurences of m_HbaName entries in your text file that you'll import into the dataclass.
I'd suggest to use a dataclass with the following fields:
_ResourceGuid and
WWN1
allowing the dataclass to use multirows.
 
 
Here is a slightly modified script, based on yours (I didn't test it, so adjustments may be neccesary)
 
 
-------------------------------
S C R I P T
-------------------------------
 
Set oShell = WScript.CreateObject("WSCript.shell")
 
dim filesys, newfolder, newfolderpath
newfolderpath = "C:\CustInv"
set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(newfolderpath) Then
  Set newfolder = filesys.CreateFolder(newfolderpath)
End If
 
oShell.run "cmd /c type c:\cnaboardmgmt.log >c:\CustInv\wwnoutput.txt", 0, True
 
 

Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
 
'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 ("{9778a2d0-8538-484d-b7da-d15b03f66335}")
 
dim objDataClass
set objDataClass = nse.AddDataBlock (objDCInstance)
 
 
Const ForReading = 1
dim wwn, strkey1
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "m_HbaName"
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\CustInv\wwnoutput.txt", ForReading)
 
 
Do Until objFile.AtEndOfStream
    strSearchString = objFile.ReadLine
    Set colMatches = objRegEx.Execute(strSearchString)  
    If colMatches.Count > 0 Then
        For Each strMatch in colMatches
            'Add a new row
            dim objDataRow
            set objDataRow = objDataClass.AddRow
 
            strkey1 = Mid(strSearchString, 19, 23)       
            'Set columns
            objDataRow.SetField 0,strkey1

        Next
    End If
Loop
 
objFile.Close
 
 
 
 
nse.SendQueued

 

Kind regards:

     Falquian

If this post is useful to you, remember to mark it as a solution ;)

HighTower's picture

Eugene, was your question answered?