Try this version.
It fixes the HBA-name error, runs over all ESXi hosts for all datastores and saves the results to a CSV file
&{foreach($esxinGet-VMHost){
foreach($canonicalNamein (Get-ScsiLun-VMHost$esx-LunTypedisk|Select-ExpandPropertyCanonicalName)){
$dsName=Get-View$esx.ExtensionData.Datastore|
where {$_.Summary.Type-eq"VMFS"-and
$_.Summary.MultipleHostAccess-and
($_.Info.Vmfs.Extent|where {$_.DiskName-eq$canonicalName})} |
Select-ExpandPropertyName
$lun=$esx.ExtensionData.Config.StorageDevice.ScsiLun|
where {$_.CanonicalName-eq$canonicalName}
$paths=$esx.ExtensionData.Config.StorageDevice.PlugStoreTopology.Device|
where{$_.Lun-eq$lun.Key} |
select-ExpandPropertyPath
$hba=$esx.ExtensionData.Config.StorageDevice.ScsiTopology.Adapter|
where{$_.Target|%{$_.Lun|where {$_.ScsiLun-eq$lun.Key}}} |%{$_.Adapter.Split('-')[2]}
foreach($pathin ($esx.ExtensionData.Config.StorageDevice.PlugStoreTopology.Path|
where {$paths-contains$_.Key})){
$hba|where {$dsName} |
Select@{N="VMHost";E={$esx.Name}},
@{N="CanonicalName";E={$canonicalName}},
@{N="Datastore";E={$dsName}},
@{N="RuntimeName";E={"$($_):C$($path.ChannelNumber):T$($path.TargetNumber):L$($path.LunNumber)"}}
}
}
}} |Sort-Object-PropertyVMHost,Datastore,CanonicalName,RuntimeName|
Export-CsvC:\LUN-DS-Runtime-Report.csv-NoTypeInformation-UseCulture