Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.scripting.vbscript > #11386 > unrolled thread

Query HBA for attached disks and drives.

Started byCésar Arévalo <arevalosoft@gmail.com>
First post2016-09-08 10:28 -0700
Last post2016-09-09 17:15 -0400
Articles 6 — 4 participants

Back to article view | Back to microsoft.public.scripting.vbscript


Contents

  Query HBA for attached disks and drives. César Arévalo <arevalosoft@gmail.com> - 2016-09-08 10:28 -0700
    Re: Query HBA for attached disks and drives. César Arévalo <arevalosoft@gmail.com> - 2016-09-08 17:58 -0700
    Re: Query HBA for attached disks and drives. GS <gs@v.invalid> - 2016-09-09 08:44 -0400
      Re: Query HBA for attached disks and drives. "Mayayana" <mayayana@invalid.nospam> - 2016-09-09 09:05 -0400
        Re: Query HBA for attached disks and drives. "Dave \"Crash\" Dummy" <invalid@invalid.invalid> - 2016-09-09 09:35 -0400
        Re: Query HBA for attached disks and drives. GS <gs@v.invalid> - 2016-09-09 17:15 -0400

#11386 — Query HBA for attached disks and drives.

FromCésar Arévalo <arevalosoft@gmail.com>
Date2016-09-08 10:28 -0700
SubjectQuery HBA for attached disks and drives.
Message-ID<e366dd19-8cdd-403f-8dc0-e4e4379f34e1@googlegroups.com>
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

[toc] | [next] | [standalone]


#11387

FromCésar Arévalo <arevalosoft@gmail.com>
Date2016-09-08 17:58 -0700
Message-ID<1798d544-ab88-46bd-acc8-543c76dde75c@googlegroups.com>
In reply to#11386
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.

[toc] | [prev] | [next] | [standalone]


#11388

FromGS <gs@v.invalid>
Date2016-09-09 08:44 -0400
Message-ID<nquara$7pg$1@dont-email.me>
In reply to#11386
> 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

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

[toc] | [prev] | [next] | [standalone]


#11389

From"Mayayana" <mayayana@invalid.nospam>
Date2016-09-09 09:05 -0400
Message-ID<nquc47$bug$1@dont-email.me>
In reply to#11388
| 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". :) 

[toc] | [prev] | [next] | [standalone]


#11390

From"Dave \"Crash\" Dummy" <invalid@invalid.invalid>
Date2016-09-09 09:35 -0400
Message-ID<nqudr1$i0o$1@dont-email.me>
In reply to#11389
Mayayana wrote:
> | 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!

[toc] | [prev] | [next] | [standalone]


#11391

FromGS <gs@v.invalid>
Date2016-09-09 17:15 -0400
Message-ID<nqv8qg$ld0$1@dont-email.me>
In reply to#11389
>> 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

[toc] | [prev] | [standalone]


Back to top | Article view | microsoft.public.scripting.vbscript


csiph-web