List the ESXi host Storage LUN Path-count, State, and DatastoreName

The below script is from Thank’s to the post “

I have tweaked the script with few lines,  to list the DataStore Name and Naaid info, so it would be nice to have all objects in single pane of view.  All credits to Eric Sarakaitis


Power CLI Script :

$initalTime = Get-Date
$date = Get-Date ($initalTime) -uformat %Y%m%d
$time = Get-Date ($initalTime) -uformat %H%M

Write-Host "nStarting time of Script is $(Get-Date ($initalTime) -uformat %H:%M:%S) "

$AllHosts = Get-cluster "Cluster-Name" | get-vmhost

#$AllHosts = get-vmhost HostName # Remove above line and Un-comment this, to run againest single Host

$reportLunPathState = @()

Write-Host "Total No of Hosts Acquired $($AllHosts.length)"

ForEach ($VMHost in $AllHosts) {

$hss = Get-View $VMHost.Extensiondata.ConfigManager.StorageSystem
Write-Host "n$(Get-Date -uformat %H:%M:%S) - $($i) of $($AllHosts.length) - " -NoNewLine; Write-Host

"$($VMHost)n" -ForegroundColor Yellow
$VMHostScsiLuns = $VMHost | Get-ScsiLun -LunType disk
ForEach ($VMHostScsiLun in $VMHostScsiLuns) {

$datastores = get-vmhost -name $VMHost | Get-datastore | Where-Object {$ -like

write-host "Finding path information for id - " -NoNewline; write-host "$VMHostScsiLun --> $($" -
ForegroundColor DarkGreen

if ($hss.FileSystemVolumeInfo.MountInfo.volume.extent -eq "$VMHostScsiLun" )
echo "equal"
$dsname = $
$VMHostScsiLunPaths = $VMHostScsiLun | Get-ScsiLunPath
$reportLunPathState += ($VMHostScsiLunPaths | Measure-Object) | Select @{N="Hostname"; E={$VMHost.Name}}, @
{N="Number of Paths"; E={$_.Count}}, Name, State, @{N="Datastore-Name"; E={$}}, @{N="Naaid"; E=
$reportLunPathState += $VMHostScsiLunPaths | Select @{N="Hostname"; E={$VMHost.Name}}, "Number of Paths", Name,
State, Datastore-Name, Naaid


$conclusionTime = Get-Date
$totalTime = New-TimeSpan $initalTime $conclusionTime

Write-Host "nScript Ending Time is $(Get-Date ($conclusionTime) -uformat %H:%M:%S) " -NoNewLine; Write-Host " With
total Time of $($totalTime.Hours):$($totalTime.Minutes):$($totalTime.Seconds)`n"

$reportLunPathState | Out-GridView

$CurrentDateTime = Get-Date -format "ddMMMyyyy-HH-mm"
$Filename = "Esx-lun-path-" + $CurrentDateTime + ".csv"
$reportLunPathState | Export-Csv "$Filename" -NoTypeInformation -UseCulture



Fyi:- With few more changes, we can also run the same on selected list of’s  imported from CSV File.