César Arévalo
2016-09-08 17:28:49 UTC
Hello team,
I'm trying to query the HBA cards on several servers to obtain HBA's info, but more important, I need to obtain what are the associated disks that comes from storage. Having this information, I will be able to obtain then, its used space and its free space.
According to MS the class HBAScsiID has the "OSDeviceName" which is the attribute I need to know to obtain the drive information. The problem is that the class is not responding back with information, it always shows nothing. The function is "QueryHBAScsiID".
Can you guys please point me in the right direction on how to make this work?
Here's my code. Sorry for the indentation... I swear it looks good in my file! LOL!
================================================
Dim strComputer : strComputer = "."
WScript.Echo QueryHBA(strComputer)
' Function to obtain the drive from a FLTMC format: "\Device\HarddiskVolume3"
function GetDriveLetterByFLTMC(strComputer, strDrive)
Dim Result : Result = ""
Dim strCommand, strVolume
Result = ""
strVolume = LCase(strDrive)
strVolume = Replace(strVolume, "\\\\", "\")
strCommand = "fltmc volumes | find /i " & QuotedStr(strVolume)
Result = Trim(ExecuteCommand(strCommand))
if Result <> "" then
Result = Split(Result, " ")(0)
end if
if Len(Result) = 2 then
GetDriveLetterByFLTMC = Result
else
Result = "N/A"
end if
GetDriveLetterByFLTMC = Result
end function
function ExecuteCommand(StrCMD)
Dim objShell, objExecObject
Dim strCommand, Result
Set objShell = CreateObject("WScript.Shell")
strCommand = "%comspec% /c " & StrCMD
Set objExecObject = objShell.Exec(strCommand)
Result = objExecObject.StdOut.ReadAll()
ExecuteCommand = Result
end function
' function that queries HBA cards
function QueryHBA(StrComputer)
On Error Resume Next
Dim objWMIDisk, colItem, objItem
Dim Result : Result = ""
Dim HBAExists : HBAExists = 0
Set objWMIDisk = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItem = objWMIDisk.ExecQuery("SELECT * FROM MSFC_FCAdapterHBAAttributes")
HBAExists = colItem.Count
if Err.Number = 0 then
For Each objItem in colItem
Result = Result & "NodeWWN: " & WWNToString(objItem.NodeWWN) & vbCrLf
Result = Result & "Active: " & objItem.Active & vbCrLf
Result = Result & "DriverName: " & objItem.DriverName & vbCrLf
Result = Result & "DriverVersion: " & objItem.DriverVersion & vbCrLf
Result = Result & "FirmwareVersion: " & objItem.FirmwareVersion & vbCrLf
Result = Result & "Model: " & objItem.Model & vbCrLf
Result = Result & "ModelDescription: " & objItem.ModelDescription & vbCrLf
Result = Result & "-------------------------------------------------" & vbCrLf
Result = Result & QueryHBAScsiID(StrComputer)
Result = Result & "-------------------------------------------------" & vbCrLf
Next
else
Err.Clear
Result = "No HBA was found in the system."
end if
QueryHBA = Result
End function
' function that queries HBA SCSI ID
function QueryHBAScsiID(StrComputer)
'On Error Resume Next
Dim objWMIDisk, colItem, objItem
Dim Result : Result = ""
Dim HBAExists : HBAExists = 0
Set objWMIDisk = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItem = objWMIDisk.ExecQuery("SELECT * FROM HBAScsiID")
WScript.Echo "Attempting to get 'HBA SCSI ID' info."
HBAExists = colItem.Count
if Err.Number = 0 then
For Each objItem in colItem
Result = Result & "ScsiBusNumber: " & objItem.ScsiBusNumber & vbCrLf
Result = Result & "ScsiTargetNumber: " & objItem.ScsiTargetNumber & vbCrLf
Result = Result & "ScsiOSLun: " & objItem.ScsiOSLun & vbCrLf
Result = Result & "OSDeviceName: " & objItem.OSDeviceName & vbCrLf
Result = Result & "-------------------------------------------------" & vbCrLf
Next
else
Err.Clear
Result = "No 'HBA SCSI ID' was found in the system."
end if
QueryHBAScsiID = Result
End function
' To format WWN
function WWNToString(ArrayWWN)
WWNToString = Hex0(ArrayWWN(0))
for i = 1 to 7
WWNToString = WWNToString & ":" & Hex0(ArrayWWN(i))
next
end function
function Hex0(n)
Hex0 = Hex(n)
if (n < &h10) then Hex0 = "0" & Hex0
end function
================================================
Thanks,
Cesar
I'm trying to query the HBA cards on several servers to obtain HBA's info, but more important, I need to obtain what are the associated disks that comes from storage. Having this information, I will be able to obtain then, its used space and its free space.
According to MS the class HBAScsiID has the "OSDeviceName" which is the attribute I need to know to obtain the drive information. The problem is that the class is not responding back with information, it always shows nothing. The function is "QueryHBAScsiID".
Can you guys please point me in the right direction on how to make this work?
Here's my code. Sorry for the indentation... I swear it looks good in my file! LOL!
================================================
Dim strComputer : strComputer = "."
WScript.Echo QueryHBA(strComputer)
' Function to obtain the drive from a FLTMC format: "\Device\HarddiskVolume3"
function GetDriveLetterByFLTMC(strComputer, strDrive)
Dim Result : Result = ""
Dim strCommand, strVolume
Result = ""
strVolume = LCase(strDrive)
strVolume = Replace(strVolume, "\\\\", "\")
strCommand = "fltmc volumes | find /i " & QuotedStr(strVolume)
Result = Trim(ExecuteCommand(strCommand))
if Result <> "" then
Result = Split(Result, " ")(0)
end if
if Len(Result) = 2 then
GetDriveLetterByFLTMC = Result
else
Result = "N/A"
end if
GetDriveLetterByFLTMC = Result
end function
function ExecuteCommand(StrCMD)
Dim objShell, objExecObject
Dim strCommand, Result
Set objShell = CreateObject("WScript.Shell")
strCommand = "%comspec% /c " & StrCMD
Set objExecObject = objShell.Exec(strCommand)
Result = objExecObject.StdOut.ReadAll()
ExecuteCommand = Result
end function
' function that queries HBA cards
function QueryHBA(StrComputer)
On Error Resume Next
Dim objWMIDisk, colItem, objItem
Dim Result : Result = ""
Dim HBAExists : HBAExists = 0
Set objWMIDisk = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItem = objWMIDisk.ExecQuery("SELECT * FROM MSFC_FCAdapterHBAAttributes")
HBAExists = colItem.Count
if Err.Number = 0 then
For Each objItem in colItem
Result = Result & "NodeWWN: " & WWNToString(objItem.NodeWWN) & vbCrLf
Result = Result & "Active: " & objItem.Active & vbCrLf
Result = Result & "DriverName: " & objItem.DriverName & vbCrLf
Result = Result & "DriverVersion: " & objItem.DriverVersion & vbCrLf
Result = Result & "FirmwareVersion: " & objItem.FirmwareVersion & vbCrLf
Result = Result & "Model: " & objItem.Model & vbCrLf
Result = Result & "ModelDescription: " & objItem.ModelDescription & vbCrLf
Result = Result & "-------------------------------------------------" & vbCrLf
Result = Result & QueryHBAScsiID(StrComputer)
Result = Result & "-------------------------------------------------" & vbCrLf
Next
else
Err.Clear
Result = "No HBA was found in the system."
end if
QueryHBA = Result
End function
' function that queries HBA SCSI ID
function QueryHBAScsiID(StrComputer)
'On Error Resume Next
Dim objWMIDisk, colItem, objItem
Dim Result : Result = ""
Dim HBAExists : HBAExists = 0
Set objWMIDisk = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItem = objWMIDisk.ExecQuery("SELECT * FROM HBAScsiID")
WScript.Echo "Attempting to get 'HBA SCSI ID' info."
HBAExists = colItem.Count
if Err.Number = 0 then
For Each objItem in colItem
Result = Result & "ScsiBusNumber: " & objItem.ScsiBusNumber & vbCrLf
Result = Result & "ScsiTargetNumber: " & objItem.ScsiTargetNumber & vbCrLf
Result = Result & "ScsiOSLun: " & objItem.ScsiOSLun & vbCrLf
Result = Result & "OSDeviceName: " & objItem.OSDeviceName & vbCrLf
Result = Result & "-------------------------------------------------" & vbCrLf
Next
else
Err.Clear
Result = "No 'HBA SCSI ID' was found in the system."
end if
QueryHBAScsiID = Result
End function
' To format WWN
function WWNToString(ArrayWWN)
WWNToString = Hex0(ArrayWWN(0))
for i = 1 to 7
WWNToString = WWNToString & ":" & Hex0(ArrayWWN(i))
next
end function
function Hex0(n)
Hex0 = Hex(n)
if (n < &h10) then Hex0 = "0" & Hex0
end function
================================================
Thanks,
Cesar