Fine, thanks.
Try this. The speed of the script is terrible, but it can definitely be optimised. Consider this a proof-of-concept version
foreach($vminGet-VM){ $luns=Get-ScsiLun-VmHost$vm.Host-LunTypeDisk
$vm.ExtensionData.Config.Hardware.Device|where {$_.gettype().Name-eq"VirtualDisk"} |%{ if("physicalMode","virtualmode"-contains$_.Backing.CompatibilityMode){ $disk=$_.Backing.LunUuid.Substring(10,32) $luns|where {$_.CanonicalName.Split(".")[1] -eq$disk} |
Select@{N="VM";E={$vm.Name}},
@{N="LunId";E={[int](Select-String":L(?<lunID>\d+)$"-InputObject$_.RuntimeName).Matches[0].Groups['lunID'].Value}} } } }