Looking for a way to tweak this script or a better script. Currently I have a two liner script that queries all poweron/off vm guest first and them goes out to get the esxi hosts. Once complete it exports the results to a csv file. The problem? It is taking a very long time to complete. The vSphere only has about 600 vms and I am guessing why it is taking a long time is that it is searching for the esx host that the vm is been query on.
Here is the code in question.
$vc = connect-viserver "VCNAME"
Get-VM | Select Name, @{N="ESX Host";E={Get-VMHost -VM $_}} | `
Export-Csv -NoTypeInformation C:\VM_Host.csv
Hope to hear from someone soon.
Thanks,
E