PowerCLI: Show HBA Path Status

When you have a lot of hosts, with a lot of LUNs, it can be difficult to keep abreast of the status of the paths for them. I have encountered issues where a path was unknowingly marked as dead, plus it’s generally a good idea to ensure that your storage paths are actually available.

Consequentially, I searched for a PowerCLI script that would give me a simple report of the status of each of the LUN paths to each of the HBAs on my hosts. I found John Milner’s post to be very helpful, and it gave me exactly the results that I wanted. However, it took forever to execute…almost 30 minutes for just one of my clusters (to be fair, that cluster has 12 hosts with > 100 LUNs and two paths to each).

Using his script as an example, and keeping a good bit of the formatting code, I have modified his script to use views of the host objects and cull the information from there. This makes it significantly faster…what took 28 minutes before now takes about 30 seconds.

$views = Get-View -ViewType "HostSystem" -Property Name,Config.StorageDevice
$result = @()
 
foreach ($view in $views | Sort-Object -Property Name) {
    Write-Host "Checking" $view.Name
 
    $view.Config.StorageDevice.ScsiTopology.Adapter |?{ $_.Adapter -like "*FibreChannelHba*" } | %{
        $hba = $_.Adapter.Split("-")[2]
 
        $active = 0
        $standby = 0
        $dead = 0
 
        $_.Target | %{ 
            $_.Lun | %{
                $id = $_.ScsiLun
 
                $multipathInfo = $view.Config.StorageDevice.MultipathInfo.Lun | ?{ $_.Lun -eq $id }
 
                $a = [ARRAY]($multipathInfo.Path | ?{ $_.PathState -like "active" })
                $s = [ARRAY]($multipathInfo.Path | ?{ $_.PathState -like "standby" })
                $d = [ARRAY]($multipathInfo.Path | ?{ $_.PathState -like "dead" })
 
                $active += $a.Count
                $standby += $s.Count
                $dead += $d.Count
            }
        }
 
        $result += "{0},{1},{2},{3},{4}" -f $view.Name.Split(".")[0], $hba, $active, $dead, $standby
    }
}
 
ConvertFrom-Csv -Header "VMHost", "HBA", "Active", "Dead", "Standby" -InputObject $result | ft -AutoSize

The result looks exactly like the original:

VMHost HBA    Active Dead Standby
------ ---    ------ ---- -------
host1  vmhba1 9      0    9
host1  vmhba2 9      0    9
host2  vmhba1 9      0    9
host2  vmhba2 9      0    9
host3  vmhba1 9      0    9
host3  vmhba2 9      0    9
host4  vmhba1 9      0    9
host4  vmhba2 9      0    9
host5  vmhba1 9      0    9
host5  vmhba2 9      0    9
host6  vmhba1 9      0    9
host6  vmhba2 9      0    9
host7  vmhba1 9      0    9
host7  vmhba2 9      0    9
host8  vmhba1 10     0    10
host8  vmhba2 10     0    10 

This is also helpful, for me, because each of my hosts should have the same number of active and standby paths…if there is more of one or the other, that’s an indication that a path is missing, or there is an extra for some reason. For example, the above is a single cluster, so they should all be identical. Multipathing appears to be good because there are the same number of active and standby paths. However, one host has an extra pair of paths…a simple check revealed that an old LUN had not been removed…no damage done, but very easy to spot with this script.

Thanks to John for doing all the hard work with formatting!