This week I have been tasked with assisting a storage engineer while he replaces a couple of Fibre Channel switches. My task was simple, check the HBAs for any “Dead” paths (See below screen shot for an example) across all the ESX hosts every hour for a weekend. We have a fair few VMHosts so this gave me the opportunity to use PowerCLI (Think PowerShell with a VMware snapin).
It didn’t take long at all to knock up a little script that can report on path states, this is what I came up with:
$VMHosts = Get-VMHost | ? { $_.ConnectionState -eq "Connected" } | Sort-Object -Property Name $results= @() foreach ($VMHost in $VMHosts) { Get-VMHostStorage -RescanAllHba -VMHost $VMHost | Out-Null [ARRAY]$HBAs = $VMHost | Get-VMHostHba -Type "FibreChannel" foreach ($HBA in $HBAs) { $pathState = $HBA | Get-ScsiLun | Get-ScsiLunPath | Group-Object -Property state $pathStateActive = $pathState | ? { $_.Name -eq "Active"} $pathStateDead = $pathState | ? { $_.Name -eq "Dead"} $pathStateStandby = $pathState | ? { $_.Name -eq "Standby"} $results += "{0},{1},{2},{3},{4},{5}" -f $VMHost.Name, $HBA.Device, $VMHost.Parent, [INT]$pathStateActive.Count, [INT]$pathStateDead.Count, [INT]$pathStateStandby.Count } } ConvertFrom-Csv -Header "VMHost","HBA","Cluster","Active","Dead","Standby" -InputObject $results | Ft -AutoSize
The output is pretty simple but does the job:
VMHost HBA Cluster Active Dead Standby ------ --- ------- ------ ---- ------- d1-vmesx-001.*************.uk vmhba2 Cluster05 40 0 24 d1-vmesx-001.*************.uk vmhba3 Cluster05 40 0 24 d2-vmesx-001.****************.uk vmhba2 Cluster02 98 0 80 d2-vmesx-001.****************.uk vmhba3 Cluster02 96 0 80 d2-vmesx-011.****************.uk vmhba2 Cluster03 76 0 88 d2-vmesx-011.****************.uk vmhba3 Cluster03 75 0 85 d2-vmesx-012.****************.uk vmhba2 Cluster03 76 0 88 d2-vmesx-012.****************.uk vmhba3 Cluster03 75 0 85 d2-vmesx-013.****************.uk vmhba1 Cluster03 83 0 85 d2-vmesx-013.****************.uk vmhba2 Cluster03 83 0 85 d2-vmesx-014.****************.uk vmhba1 Cluster03 83 0 85 d2-vmesx-014.****************.uk vmhba2 Cluster03 83 0 85 d2-vmesx-015.****************.uk vmhba1 Cluster03 83 0 85 d2-vmesx-015.****************.uk vmhba2 Cluster03 83 0 85 d2-vmesx-016.****************.uk vmhba1 Cluster03 83 0 85 d2-vmesx-016.****************.uk vmhba2 Cluster03 83 0 85 d2-vmesx-017.****************.uk vmhba1 MSCS Cluster01 44 0 308 d2-vmesx-017.****************.uk vmhba2 MSCS Cluster01 44 0 308 d2-vmesx-018.****************.uk vmhba1 MSCS Cluster01 44 0 308 d2-vmesx-018.****************.uk vmhba2 MSCS Cluster01 44 0 308 d2-vmesx-019.****************.uk vmhba1 Cluster04 68 0 52 d2-vmesx-019.****************.uk vmhba2 Cluster04 68 0 52 d2-vmesx-021.****************.uk vmhba1 Cluster04 68 0 52 d2-vmesx-021.****************.uk vmhba2 Cluster04 68 0 52
If you wanted to work with this information further then I would suggest creating a custom object and populating the properties with Add-Member instead of doing the format string method above, I just did that as it’s quick. Well this is my first PowerCLI script, I hope to share some more.
Bye for now.
jfrmilner