Hello, trevor12087-
One thing that comes to mind is the way in which you are getting the hard disk info for the given VM. It appears that you are calling Get-HardDisk for each input line from the CSV. You could optimize things by calling this cmdlet fewer times (say, one time per VM). Then, store the VM's harddisk objects in an array, and _then_ get the desired info about each harddisk (disk name as found by ScsiCanonicalName). That will be a more code (say, some Group-Object action), but should result in faster overall execution.
But, your want to speed up Get-HardDisk, or, at least speed up getting the harddisk info that you desire, reminded me that we at vNugglets wrote such a function a while back. This function gets info for VM hard disks -- both for "regular" virtual disks and for RDMs (including ScsiCanonicalName). So, I have now posted said function at Get VM Disks and RDMs via PowerCLI.
This function will help in your case -- not by speeding up Get-HardDisk, but by eliminating the dependency upon it (not using it at all). You can use the function to get the hard disk info that you want / need, and with significant speed increases. For example, I tested against a particular VM with RDMs:
method of disk info retrieval | run duration |
---|
Get-HardDisk cmdlet | ~26 s |
Get-VMDiskAndRDM function from vNugglets.com | ~2.2 s |
So, about 10x performance increase -- nice! And, that is w/o re-writing as mentioned in paragraph 0 above. You get further increase performance by only calling the function once per VM.
Anyway, you can read all about that function at, again, Get VM Disks and RDMs via PowerCLI. How does that do for you?