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

The below script is from Vmwareadmins.com. Thank’s to the post “http://www.vmwareadmins.com/list-the-path-and-path-state-for-every-vsphere-datastore-using-powercli/

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
$i++
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 {$_.extensiondata.info.vmfs.extent.diskname -like
$VMHostScsiLun.canonicalname}

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

if ($hss.FileSystemVolumeInfo.MountInfo.volume.extent -eq "$VMHostScsiLun" )
{
echo "equal"
}
$dsname = $hss.FileSystemVolumeInfo.MountInfo.volume.name
$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={$datastores.name}}, @{N="Naaid"; E=
{$VMHostScsiLun.canonicalname}}
$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 naa.id’s  imported from CSV File.