Find HBA details with Get-WmiObject

When setting up connectivity between SANs and hosts knowing the HBA information is important. With Pure Storage the WWNs are automatically discovered if zoned properly to the fabric. So from the GUI you will see the WWNs. But who do those WWNs belong to? Knowing the associated ports to host is important for setting up all the individual hosts with proper pathing.

But first a question, “why use Get-WmiObject when there is the easy way using Get-InitiatorPort?” Well duh, because WMI is cooler. With the built in cmdlet, Get-InitiatorPort, you can retrieve the below which provides all the details needed.

PS C:\Users\Administrator.MSLAB\Desktop\github\powershell-toolkit> Get-InitiatorPort

InstanceName NodeAddress PortAddress ConnectionType
------------ ----------- ----------- --------------
PCI\VEN_1137&DEV_0045&SUBSYS_00841137&REV_A2\0025B5FFFF22003F00_0 20000025b544000e 20000025b522003f Fibre Channel
PCI\VEN_1137&DEV_0045&SUBSYS_00841137&REV_A2\0025B5FFFF22000F00_0 20000025b544000e 20000025b522000f Fibre Channel
PCI\VEN_1137&DEV_0045&SUBSYS_00841137&REV_A2\0025B5FFFF66003F00_0 20000025b544000e 20000025b566003f Fibre Channel
PCI\VEN_1137&DEV_0045&SUBSYS_00841137&REV_A2\0025B5FFFF66000F00_0 20000025b544000e 20000025b566000f Fibre Channel

Using Windows Management Instrumentation (WMI) there are a lot of other properties that can be queried. Below is an example of when I setup the initial lab environment at Pure Storage for working on Microsoft solutions.

From November 27.2013 —–

I was setting up a new Pure Storage FA-420 array this past week and needed the Host Bus Adapter (HBA) information, specifically the WWNodeName and WWPortName for the QLogic 2562, so I put together this PowerShell that provides all the details. Currently the script takes a single server name and should be run on the server that has the HBA installed. This was a quick solution and I wanted to get this posted but I’ll be tweaking the script to handle multiple servers and different output options.

function Get-HBAInfo {
   [CmdletBinding()]
   Param
   (
     [Parameter(Mandatory=$false, ValueFromPipeline=$true, Position=0)]
     $ComputerName
   )

   Begin 
   {
      $Namespace = "root\WMI"
   } Process {
     $port = Get-WmiObject -Class MSFC_FibrePortHBAAttributes -Namespace $Namespace @PSBoundParameters
     $hbas = Get-WmiObject -Class MSFC_FCAdapterHBAAttributes -Namespace $Namespace @PSBoundParameters
     $hbaProp = $hbas | Get-Member -MemberType Property, AliasProperty | Select -ExpandProperty name | ? {$_ -notlike "__*"}
     $hbas = $hbas | Select $hbaProp
     $hbas | %{ $_.NodeWWN = ((($_.NodeWWN) | % {"{0:x2}" -f $_}) -join ":").ToUpper() }
 
     ForEach($hba in $hbas) {
       Add-Member -MemberType NoteProperty -InputObject $hba -Name FabricName -Value (
        ($port |? { $_.instancename -eq $hba.instancename}).attributes | `
        Select `
        @{Name='Fabric Name';Expression={(($_.fabricname | % {"{0:x2}" -f $_}) -join ":").ToUpper()}}, `
        @{Name='Port WWN';Expression={(($_.PortWWN | % {"{0:x2}" -f $_}) -join ":").ToUpper()}} 
        ) -passThru
    }
  }
}
Get-HBAInfo $env:COMPUTERNAME

For formatting using the OutGridView, Format-Table or output to a file using Out-File.

Thanks,
Barkz

8 comments
  1. I’m trying to get more information out of the Fibre Channel Adapters on Windows Server 2016.
    Can you help please?

  2. What are the meanings of portstate attribute while you get wmi information from MSFC_FibrePortHBAAttributes class. There are 2 , 6 and maybe some other values but nowhere says what do these numbers mean.

    • Hi Rakesh —

      By default the Get-HBAInfo cmdlet uses the -ComputerName parameter with $env:COMPUTERNAME. Instead of just running the cmdlet use:

      Get-HBAInfo -ComputerName [remote_computername]

      HTH — Barkz

Add Comment

Required fields are marked *. Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.