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
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
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
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?
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
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
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
Yes !!!! Thank you.
Thanks Luc for sharing this info.
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?
Try like this
$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
Worked beautifully!! Thanks again, you are amazing.
Hi LucD,
Thanks for the script, wondering if you could add the LUN name as well to the output. 🙂
Dipak
The LUN column in the CSV should have those
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
Canonical Name, looking for both LUN Naa ID and Canonical Names so it's easier to look for it in the vCenter. 🙂
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
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
Dipak - Have you figured this out yet? Adding the Datastore Name would be helpful.