Automation

 View Only
Expand all | Collapse all

See number of paths per LUN per host

  • 1.  See number of paths per LUN per host

    Posted Mar 21, 2015 12:56 PM

    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



  • 2.  RE: See number of paths per LUN per host
    Best Answer

    Posted Mar 21, 2015 10:14 PM

    You mean something like this ?

    $esxName = 'MyEsx'

    $esx = Get-VMHost -Name $esxName

    $esxcli = Get-EsxCli -VMHost $esxName

    $hba = Get-VMHostHba -VMHost $esx -Type FibreChannel | Select -ExpandProperty Name

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

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

    Group-Object -Property Device |

    Select @{N='LUN';E={$_.Name}},@{N='#Path';E={$_.Group.Count}}



  • 3.  RE: See number of paths per LUN per host

    Posted Mar 22, 2015 04:59 PM

    Thank you Luc !!!

    Is there a way I can put the output in variables? Or in other words, how do I paste @{N='LUN';E={$_.Name}},@{N='#Path';E={$_.Group.Count}} into $LUN and $NrPaths?



  • 4.  RE: See number of paths per LUN per host

    Posted Mar 22, 2015 05:08 PM

    Can $LUN and $NRPaths be arrays, or hwo do you want to use $LUN and $NRPaths ?



  • 5.  RE: See number of paths per LUN per host

    Posted Mar 22, 2015 05:13 PM

    Well, I'm going to do this for a number of vCenters and usually I work like this, because my PowerShell syntax is not that good yet :-)

    $report= @()

    foreach( $esxvm in $esxilist){

         foreach( lun in number of luns of this host ){

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

         $row.ESXihost = $esxvm.name

         $row.Lun = devicename

         $row.NrPaths = total of paths

         $report += $row

    }

    }

    $report | export-csv



  • 6.  RE: See number of paths per LUN per host

    Posted Mar 22, 2015 08:48 PM

    Got it, try like this

    $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



  • 7.  RE: See number of paths per LUN per host

    Posted Mar 23, 2015 10:22 AM

    Yes !!!! Thank you.



  • 8.  RE: See number of paths per LUN per host

    Posted May 21, 2016 10:55 AM

    Thanks Luc for sharing this info.



  • 9.  RE: See number of paths per LUN per host

    Posted Oct 17, 2018 05:13 PM

    Hi LucD - This is great, I know the question has been answered, let me know if you want me to start a new one if i need to.

    Are we able to add VM count per host to this output?



  • 10.  RE: See number of paths per LUN per host

    Posted Oct 17, 2018 05:28 PM

    Try 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 Device | % {

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

       $row.ESXihost = $esx.name

       $row.Lun = $_.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



  • 11.  RE: See number of paths per LUN per host

    Posted Oct 17, 2018 05:41 PM

    Worked beautifully!! Thanks again, you are amazing.



  • 12.  RE: See number of paths per LUN per host

    Posted Feb 23, 2021 08:08 PM

    Hi LucD,

    Thanks for the script, wondering if you could add the LUN name as well to the output.

    Dipak

     



  • 13.  RE: See number of paths per LUN per host

    Posted Feb 23, 2021 08:20 PM

    The LUN column in the CSV should have those



  • 14.  RE: See number of paths per LUN per host

    Posted Mar 15, 2021 05:34 PM

    Hi LucD,

    Nah the CSV file doesn't have the LUN Name, see attached

    Sorry for the Late Response. 



  • 15.  RE: See number of paths per LUN per host

    Posted Mar 15, 2021 05:35 PM

    here is what I am using

    $outputFile = "esx-lun-path-" + $((Get-Date).ToString("yyyy_MM_dd_HH_mm_ss")) + ".csv"
    $filelist=Read-Host "Please Enter Text file with ESXi hosts Names"
    $esxName=gc $filelist | %{get-vmhost $_*}
    # $esxName = get-vmhost
    $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 Device | % {

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

    $row.ESXihost = $esx.name

    $row.Lun = $_.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 -Path $outputFile -NoTypeInformation -UseCulture

     



  • 16.  RE: See number of paths per LUN per host

    Posted Mar 15, 2021 06:02 PM

    The column with the naa.* entries are the LUN names (or canonical names).
    What do you mean by LUN name?



  • 17.  RE: See number of paths per LUN per host

    Posted Mar 15, 2021 06:26 PM

    Canonical Name, looking for both LUN Naa ID and Canonical Names so it's easier to look for it in the vCenter.  



  • 18.  RE: See number of paths per LUN per host

    Posted Mar 15, 2021 06:50 PM

    If it is not the Canonical name, then I have no clue what you mean by "LUN Naa ID"



  • 19.  RE: See number of paths per LUN per host

    Posted Mar 15, 2021 07:27 PM

    I am so sorry, mixed up both names, I indented to Say "Datastore Name" and "Canonical Name,"

     

    Name                                  CanonicalName
    ----                                         -------------

    Datastore_x2_18         naa.514f0c5732e0001a
    Datastore_x2_19         naa.514f0c5732e0001b
    Datastore_x2_2            naa.514f0c5732e0001c
    Datastore_x2_20         naa.514f0c5732e0001d
    Datastore_x2_3            naa.514f0c5732e0001e
    Datastore_x2_4             naa.514f0c5732e0001f



  • 20.  RE: See number of paths per LUN per host

    Posted Aug 23, 2021 07:33 PM

    Dipak - Have you figured this out yet?  Adding the Datastore Name would be helpful.  



  • 21.  RE: See number of paths per LUN per host

    Posted Nov 03, 2022 08:41 AM

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



  • 22.  RE: See number of paths per LUN per host

    Posted Nov 03, 2022 10:01 AM

    Try grouping per Adapter.

    Something like this



  • 23.  RE: See number of paths per LUN per host

    Posted Nov 03, 2022 12:16 PM

    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



  • 24.  RE: See number of paths per LUN per host

    Posted Nov 03, 2022 12:35 PM

    Group on both Adapter and LUN

     

     



  • 25.  RE: See number of paths per LUN per host

    Posted Nov 03, 2022 02:49 PM

    while running this new script i am getting below error.

    chinnu2705_0-1667486895237.png

     



  • 26.  RE: See number of paths per LUN per host

    Posted Nov 03, 2022 05:26 PM

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



  • 27.  RE: See number of paths per LUN per host

    Posted Nov 03, 2022 05:27 PM

    Thanks got the required output