Hi all
Working on an environment w/500+ ESX hosts and more than 2000 VMs, so the performance of my PowerCLI code is essential.
I'm very fond of get-view and use it whenever possible, alas, sometimes you need additional info...and it's slow...
An example fetching additional CD/DVD-ROM info lacking from views (like ISO path) :
$vm = Get-View -ViewType VirtualMachine -Property Name, Config.Hardware.Device -Filter @{"Name"="myVM"}
measure-command{get-vm -name $vm.name} | fl TotalSeconds
11,6428104 seconds
measure-command{get-vm -id $vm.MoRef} | fl TotalSeconds
0,6073553 seconds
measure-command{get-cddrive -vm $vm.name} | fl TotalSeconds
11,5655317 seconds
measure-command{get-vm -id $vm.MoRef | get-cddrive} | fl TotalSeconds
0,9418873 seconds
My experience is that lookups using names instead of IDs are about 10 times slower.
So I end up having my code connecting to my vCenter server twice to get the cd drive...
Now the question:
Several functions, like Get-CDDrive, do have the -id parameter.
How do I use it? Can I find it within the view or do I have to start constructing it (hack) based on the VMs MoRef and the drive's device ID?
Related post: https://communities.vmware.com/thread/254257