I'm working on a small script that will eventually be used to remove RDMs, but for now just for testing purposes I'm only calling Get-HardDisk.
My current code is as such:
Get-HardDisk -VM $vm -DiskType RawPhysical | where { $_.ScsiCanonicalName -eq $i.GKUUID}
where $vm is an object from a previous get-vm call and $i.GKUUID is the naa # from a CSV file.
I'm sure that my slow down is from this line, as even when the whole CSV file contains RDMs from only one VM, so that get-vm is only called once, the script still takes a very long time.
I'm pretty new to powerCLI in general, so I'm hoping that is a faster way to locate the HardDisk.
Here is the information I am provided with:
Action ServerName GKUUID GKHostDeviceName ESXCluster GKDeviceName ArrayName
Remove "vm name" 00000000000000000000000000000000 vmhba:CX:TX:LX "cluster name" 0000X VMAX-0000 \\.\PHYSICALDRIVE34
Thanks
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?
That cmdlet shouldn't take that long, or do you have that many LUNs connected ?
What's in the rest of the script ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
foreach ($i in $inputarray) { | |||
if($tempVM -ne $i.servername){ | |||
$tempVM = $i.servername | |||
$vm = get-vm $i.ServerName |
}
$result = New-Object System.Object | |||
$result = Get-HardDisk -VM $vm -DiskType RawPhysical | where { $_.ScsiCanonicalName -eq $i.GKUUID} | Select Name | |||
$result | Add-Member -MemberType NoteProperty -Name "Server Name" -Value $i.ServerName | |||
$output += $result | } |
So get-vm is only being called when the VM name in the input file differs from the previous and the input file is sorted so all drives from the same VM are grouped together. And like I said, I've tested it with only RDMs from 1 VM and it still took a long time.
There can be upwards of 30 LUNs for each VM.
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?
Thanks for the response.
I had already rewritten my code, with the same idea that you mentioned, such that I only call Get-HardDisk once per VM and store the results in an array. As you figured, it was much faster.
I'll definitely check out your function and see how it compares.
Just some feedback.
Get-VMDiskAndRDM vs. Get-HardDisk, when they are both being called only once per VM, were equivalent to each other in speed for my tests.
Hello, trevor12087-
Sounds like you might not quite be taking full advantage of that function. In the scenario you outlined, you do a Get-VM and then a Get-HardDisk. When using Get-VMDiskAndRDM, you do not need to do either of the Get-VM or Get-HardDisk calls.
By the way that you report that there is no speed difference, it seems that you are still using the Get-VM call in your code, and just replacing the Get-HardDisk with the Get-VMDiskAndRDM call.
The speed comparisons that I gave before were using:
Get-VM and Get-HardDisk way:
Get-VM myVM0 | Get-HardDisk | ?{$_.ScsiCanonicalName -eq "naa.60000970000111102222333333444444"}
Get-VMDiskAndRDM way:
Get-VMDiskAndRDM myVM0 | ?{$_.ScsiCanonicalName -eq "naa.60000970000111102222333333444444"}
Are you removing both the Get-VM and Get-HardDisk calls in your current code revision?
You were indeed correct.
Removing the Get-VM call and modifying my Get-VMDiskAndRDM cut my time to about 1/4 of before.
Hello-
Great, glad to hear that it helped! Thanks for letting us know. Enjoy!