Discussion:
Query HBA for attached disks and drives.
(too old to reply)
César Arévalo
2016-09-08 17:28:49 UTC
Permalink
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
César Arévalo
2016-09-09 00:58:50 UTC
Permalink
I found that my code is wrong... anyway, I found a paper where the author explains in a very detailed way what and how get information from FC. That's cool.

The paper's URL: https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwjt6oL-iIHPAhVMFj4KHaJGAE0QFggeMAA&url=http%3A%2F%2Fdownload.microsoft.com%2Fdownload%2F9%2Fc%2F5%2F9c5b2167-8017-4bae-9fde-d599bac8184a%2Ffctopology.doc&usg=AFQjCNH0M4m2iInLFKN-JiPiRNwy_L331w&sig2=W9axUoqsp_t8TjEFJa9mfQ

I'm working on the new code... I'll post the results upon testing.
GS
2016-09-09 12:44:23 UTC
Permalink
Post by César Arévalo
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)
"\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.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
Try using WMI. It serves me very well for any 'system' info I need!
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Mayayana
2016-09-09 13:05:14 UTC
Permalink
| Try using WMI. It serves me very well for any 'system' info I need!
|

His code is using WMI. Though I have no idea
what an HBA is. Maybe that's because I'm not
on his "team". :)
Dave "Crash" Dummy
2016-09-09 13:35:30 UTC
Permalink
Post by Mayayana
| Try using WMI. It serves me very well for any 'system' info I need!
|
His code is using WMI. Though I have no idea
what an HBA is. Maybe that's because I'm not
on his "team". :)
It's either Home Builders Association or Host Bus Adapter:
https://en.wikipedia.org/wiki/Host_adapter
--
Crash

I'm not archaic, I'm retro!
GS
2016-09-09 21:15:57 UTC
Permalink
Post by Mayayana
Post by GS
Try using WMI. It serves me very well for any 'system' info I need!
His code is using WMI. Though I have no idea
what an HBA is. Maybe that's because I'm not
on his "team". :)
That's why I suggested using WMI. QueryHBA looks foreign to any WMI
classes I use for drives info, and so I got the impression it's
something other than!
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Loading...