How to Count Number of Paths in Fibre Channel VMWare Storage Using PowerCLI – VirtuallyThatGuy

A quick script to count the number of paths for FC ESxi HBAs for audit and troubleshooting connectivity issues using powercli.

##Count Number of Paths Fibre Channel

$esxName = 'uk3p-esxi01*','uk3p-esx02*','uk3p-esx03*'
$report= @()
$esxilist = Get-VMHost -Name $esxName
 
foreach( $esxvm in $esxilist){
$esx = Get-VMHost -Name $esxvm
$esxcli = Get-EsxCli -VMHost $esxvm
$hba = Get-VMHostHba -VMHost $esx -TypeFibreChannel | Select -ExpandProperty Name
$esxcli.storage.core.path.list() |
Where{$hba -contains $_.Adapter} |
Group-Object -Property Device | %{
     $row = "" | Select ESXihost, Lun, NrPaths
     $row.ESXihost = $esxvm.name
     $row.Lun = $_.Name
     $row.NrPaths = $_.Group.Count
     $report += $row
  }
}
 
$report | Export-Csv esx-lun-path.csv -NoTypeInformation -UseCulture


##Count Number of Paths Fibre Channel

 

$esxName​​ =​​ 'uk3p-esxi01*','uk3p-esx02*','uk3p-esx03*'

$report=​​ @()

$esxilist​​ =​​ Get-VMHost​​ -Name​​ $esxName

​​ 

foreach(​​ $esxvm​​ in​​ $esxilist){

$esx​​ =​​ Get-VMHost​​ -Name​​ $esxvm

$esxcli​​ =​​ Get-EsxCli​​ -VMHost​​ $esxvm

$hba​​ =​​ Get-VMHostHba​​ -VMHost​​ $esx​​ -TypeFibreChannel​​ |​​ Select​​ -ExpandProperty​​ Name

$esxcli.storage.core.path.list()​​ |

Where{$hba​​ -contains​​ $_.Adapter}​​ |

Group-Object​​ -Property​​ Device​​ |​​ %{

 ​​ ​​ ​​ ​​​​ $row​​ =​​ ""​​ |​​ Select​​ ESXihost,​​ Lun,​​ NrPaths

 ​​ ​​ ​​ ​​​​ $row.ESXihost​​ =​​ $esxvm.name

 ​​ ​​ ​​ ​​​​ $row.Lun​​ =​​ $_.Name

 ​​ ​​ ​​ ​​​​ $row.NrPaths​​ =​​ $_.Group.Count

 ​​ ​​ ​​ ​​​​ $report​​ +=​​ $row

 ​​​​ }

}

​​ 

$report​​ |​​ Export-Csv​​ esx-lun-path.csv​​ -NoTypeInformation​​ -UseCulture

 

​​ 

 

You May Also Like

About the Author: VirtuallyThatGuy

1 Comment

  1. I recently updated my powercli version and realised you can just issue this command to retrieve WWN from a Host

    Get-VMHost uk3p-esxi01.lab.local | Get-VMHostHba | ft -a

Leave a Reply

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