Gabrie1
Commander
Commander

See number of paths per LUN per host

Jump to solution

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

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

18 Replies
LucD
Leadership
Leadership

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

Gabrie1
Commander
Commander

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
0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
Gabrie1
Commander
Commander

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
0 Kudos
LucD
Leadership
Leadership

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

Yes !!!! Thank you.

http://www.GabesVirtualWorld.com
0 Kudos
impranayk
Enthusiast
Enthusiast

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
0 Kudos
FrankG203
Contributor
Contributor

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?

0 Kudos
LucD
Leadership
Leadership

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

Worked beautifully!! Thanks again, you are amazing.

0 Kudos
Dipak
Enthusiast
Enthusiast

Hi LucD,

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

Dipak

 

0 Kudos
LucD
Leadership
Leadership

The LUN column in the CSV should have those


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

0 Kudos
Dipak
Enthusiast
Enthusiast

Hi LucD,

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

Sorry for the Late Response. 

0 Kudos
Dipak
Enthusiast
Enthusiast

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

 

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
Dipak
Enthusiast
Enthusiast

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

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
Dipak
Enthusiast
Enthusiast

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

0 Kudos