Hi,
The attached below would do your job, bold and italic lines are the ones I've added in:
$report = foreach($esx in Get-VMHost){
foreach($hbaKey in ($esx.Extensiondata.Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -like "*FibreChannelHba*"})){
if($hbaKey.Target){
foreach($tgtKey in $hbaKey.Target){
foreach($lunKey in $tgtKey.Lun){
$hba = $esx.Extensiondata.Config.StorageDevice.HostBusAdapter | where {$_.Key -eq $hbaKey.Adapter}
$lun = $esx.Extensiondata.Config.StorageDevice.ScsiLun | where {$_.Key -eq $lunKey.ScsiLun}
$datastore = $esx | Get-Datastore | Where-Object {(%{$_.ExtensionData.Info.Vmfs.Extent} | %{$_.DiskName}) -match $lun.CanonicalName}
Select-Object -InputObject $lun -Property @{N="Cluster";E={Get-Cluster -VMHost $esx | %{$_.Name}}},@{N="Host";E={$esx.Name}},@{N="Datastore";E={$datastore | %{$_.Name}}},@{N="FreeSpace";E={$datastore | %{$_.FreeSpaceGB}}},@{N="Capacity";E={$datastore | %{$_.CapacityGB}}},@{N="Virtual Machines";E={[string]::Join(",", (Get-VM -Datastore $datastore))}},
@{N="HBA";E={$hba.Device}},
CanonicalName,DisplayName,@{N="LUN";E={$lunKey.Lun}}
}
}
}
}
}
$report | Export-Csv "C:\temp\lun-report.csv" -NoTypeInformation -UseCulture