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


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

Query HBA for attached disks and drives.

Newsgroups microsoft.public.scripting.vbscript
Date 2016-09-08 10:28 -0700
Message-ID <e366dd19-8cdd-403f-8dc0-e4e4379f34e1@googlegroups.com> (permalink)
Subject Query HBA for attached disks and drives.
From César Arévalo <arevalosoft@gmail.com>

Show all headers | View raw


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

Back to microsoft.public.scripting.vbscript | Previous | NextNext in thread | Find similar


Thread

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

csiph-web