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
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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}}


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

View solution in original post

26 Replies
LucD
Leadership
Leadership
Jump to solution

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}}


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

Gabrie1
Commander
Commander
Jump to solution

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?

http://www.GabesVirtualWorld.com
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

Reply
0 Kudos
Gabrie1
Commander
Commander
Jump to solution

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

http://www.GabesVirtualWorld.com
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

Gabrie1
Commander
Commander
Jump to solution

Yes !!!! Thank you.

http://www.GabesVirtualWorld.com
Reply
0 Kudos
impranayk
Enthusiast
Enthusiast
Jump to solution

Thanks Luc for sharing this info.

-------------------------------------------------------------------------
Follow me @ www.vmwareinsight.com
Please consider marking this answer "correct" or "helpful" if you found it useful

Pranay Jha | Blog: http://vmwareinsight.com
vExpert 2016/2017, VCAP5-DCD/DCA, VCP5-DCV, VCA-Cloud, VCE-CIA, MCSE, MCITP
Reply
0 Kudos
FrankG203
Enthusiast
Enthusiast
Jump to solution

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?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

FrankG203
Enthusiast
Enthusiast
Jump to solution

Worked beautifully!! Thanks again, you are amazing.

Reply
0 Kudos
Dipak
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

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

Dipak

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The LUN column in the CSV should have those


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

Reply
0 Kudos
Dipak
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

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

Sorry for the Late Response. 

Reply
0 Kudos
Dipak
Enthusiast
Enthusiast
Jump to solution

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

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

Reply
0 Kudos
Dipak
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

Reply
0 Kudos
Dipak
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
FrankG203
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos