To save the results to a CSV file use it like this
&{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}} } } }} |Export-CsvC:\report.csv-NoTypeInformation-UseCulture
For me it seems to produce results. But mind, like I already stated, the script will run a very long time in a bigger environment.
What are the specs of your environment ? vSphere version, PowerCLI version ...