Try something like this
Get-View-ViewType VirtualMachine -SearchRoot $cluster.MoRef-PipelineVariable vm |
ForEach-Object-Process {
$vm.Config.Hardware.Device|where{$_ -is [VMware.Vim.VirtualSCSIController]} |
ForEach-Object-Process {
$ctrl= $_
$vm.Config.Hardware.Device|where{$ctrl.Device-contains $_.Key} |
ForEach-Object-Process {
New-Object-TypeName PSObject -Property ([ordered]@{
VMname=$vm.Name
SCSIController=$ctrl.DeviceInfo.Label
DiskName= $_.DeviceInfo.Label
SCSI_ID="$($ctrl.BusNumber) : $($_.UnitNumber)"
DeviceName= $_.DeviceInfo.Label
DiskFile= $_.Backing.FileName
DiskSize= $_.CapacityInKB*1KB/1GB
DiskType=&{if($_.Backing.Gettype().Name -match'flat'){'Flat'}
else{
if($_.Backing.CompatibilityMode-match'physical'){'RawPhysical'}else{'RawVirtual'}
}}
CanonicalName=&{
if($_.Backing.Gettype().Name -notmatch'flat'){
$dev= $_
$esx=Get-View-Id $vm.RunTime.Host
$lun=$esx.Config.StorageDevice.ScsiLun|where{$_.Descriptor.Id-contains$dev.Backing.DeviceName}
$lun.CanonicalName
}
}
})
}
}
#}
} |Sort-Object-Property VMname, Diskname |Out-GridView