With an extra condition in the Where-clause
foreach($vm in Get-VM){
$diskFiles = $vm.ExtensionData.LayoutEx.Disk | %{$_.Chain} | %{$_.FileKey}
$vm.ExtensionData.LayoutEx.File | where{$diskFiles -contains $_.Key -and $_.Type -eq "diskExtent"} |
Select @{N="VM";E={$vm.Name}},Name,Size
}
Note that I changed the previous code as well, you have to use the Key with the index numbers, not the array index.
Most of the time it will work, but there are exceptions where the Key doesn't correspond with the array index.