Here you go: $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} $freespace = $datastore | %{$_.FreeSpaceGB} $capacity = $datastore | %{$_.CapacityGB} Select-Object -InputObject $lun -Property @{N="Cluster";E={Get-Cluster -VMHost $esx | %{$_.Name}}},@{N="Host";E={$esx.Name}},@{N="Datastore";E={$datastore | %{$_.Name}}},@{N="Free Space (GB)";E={$freespace}},@{N="Capacity (GB)";E={$capacity}},@{N="Used Space (GB)";E={$capacity - $freespace}},@{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
↧