VMware Cloud Community
Gabrie1
Commander
Commander
Jump to solution

See number of paths per LUN per host

Hi

I've seen so many scripts these past days on how to check my storage connections, but I still don't get the info I'm searching for. I would like to see per host for each LUN (RDM / Datastore) the number of paths. I have found scripts that show me the active paths, dead paths and working paths, but none of these helps me to see the number of paths per host.

The following script from Luc Dekens seems to be a good starting point, but again this only shows totals per hba, I need it per host per lun.

$esx = Get-VMHost vcdvm580.virtualcenter.lan

foreach($hba in (Get-VMHostHba -VMHost $esx -Type "FibreChannel")){

     $target = ((Get-View $hba.VMhost).Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -eq $hba.Key}).Target

     $luns = Get-ScsiLun -Hba $hba  -LunType "disk"

     $nrPaths = ($target | %{$_.Lun.Count} | Measure-Object -Sum).Sum

     Write-Host $hba.Device "Targets:" $target.Count "Devices:" $luns.Count "Paths:" $nrPaths

}

Any help would be appreciated.

Gabrie

http://www.GabesVirtualWorld.com
26 Replies
chinnu2705
Contributor
Contributor
Jump to solution

can we modify the script to get result per HBA how many paths are available

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try grouping per Adapter.

Something like this

$esxName = 'esx1', 'esx2','esx3'
$report = @()

foreach ($esx in Get-VMHost -Name $esxName) {
  $esxcli = Get-EsxCli -VMHost $esx
  $hba = Get-VMHostHba -VMHost $esx -Type FibreChannel | Select -ExpandProperty Name
  $esxcli.storage.core.path.list() |
   Where {$hba -contains $_.Adapter} |
   Group-Object -Property Adapter | % {
   $row = "" | Select ESXihost, Adapter, NrPaths, NrVM
   $row.ESXihost = $esx.name
   $row.Adapter = $_.Name
   $row.NrPaths = $_.Group.Count
   $row.NrVM = (Get-View -Id $esx.ExtensionData.Vm -Property Name, Config.Template | where {-not $_.ExtensionData.Config.Template}).Count
   $report += $row
  }
}

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
chinnu2705
Contributor
Contributor
Jump to solution

Hello LUCD,

Thanks for help. Can we modify your previous below script to get output of esxi host name, lun id, adapter and path number. So we can identify for each lun, from each adapter how many paths are present.

$esxName = 'esx1','esx2','esx3'

$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 -Type FibreChannel | 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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Group on both Adapter and LUN

 

$esxName = 'esx1','esx2','esx3'
$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 -Type FibreChannel | Select -ExpandProperty Name
$esxcli.storage.core.path.list() |
Where{$hba -contains $_.Adapter} |
Group-Object -Property Adapter,Device | %{
     $row = "" | Select ESXihost, Adapter, Lun, NrPaths
     $row.ESXihost = $esxvm.name
     $row.Adapter = $_.Name.Replace(' ','').Split(',')[0]
     $row.Lun = $_.Name.Replace(' ','').Split(',')[1]
     $row.NrPaths = $_.Group.Count
     $report += $row
  }
}
 
$report | Export-Csv esx-lun-path.csv -NoTypeInformation -UseCulture

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
chinnu2705
Contributor
Contributor
Jump to solution

while running this new script i am getting below error.

chinnu2705_0-1667486895237.png

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I forgot to add the Adapter property.
The code above is corrected.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

chinnu2705
Contributor
Contributor
Jump to solution

Thanks got the required output

Reply
0 Kudos