That is not in the script you included, and, as you said, the $VMs variable was empty.
Copy error:) Couldn't copied that line. $VMs is empty before assigning the command GET_VM
There must be going something wrong with that Get-VM.
I believe, the data is huge, is there any rely on session. VM will move from one host to another frequently Just FYI
Do you see the VMs on screen when you just do a 'Get-VM' from the PowerCLI prompt ?
On both vCenters ?
I can. We have around 9000 VM
FYI: PowerCLI > get-vm | Export-csv VMlist.csv
It took 3 hours to get the data.