Is there any reason (and any way round it) that the get-scsilun call seems to be so expensive?
I'm enumerating through all the datastores on a server, and I'm doing a call to get all the scsiluns for a canonicalname. Each call to get-scsilun is taking 22 seconds to complete - and with 79 datastores on each server, it's taking almost 30 mins per server to run through the script (and therefore 3 hours to complete on our cluster of 6 machines).
Is there any way to speed up this call?
I'm currently using
$scsilun = get-scsilun -vmhost $objvmhost -canonicalname $lun
where $objvmhost is returned from $objvmhost = get-vmost vmserver01.local. I initially tried it passing the vmhost name as text, and letting the toolkit deal with it. Changing to passing the object made no difference in the speed.
My psuedo code for what I'm trying to do is...
get-datastores on host
for each datastore
{
get the first extent of the datastore
for each lun in the first extent
{
get-scsilun <- This is the slow part
get-scsilunpath for the lun
display active path -or- set active path to the lunpath we want
}
}
Is there a better way to loop through all the datastores and display/set the active paths?
Graham
You might consider taking the Get-ScsiLun call out of the loop.
I normally do 1 Get-ScsiLun call and store the results in a hash table.
For example:
$lunTab = @{}
Get-ScsiLun | %{
$lunTab.Add($_.CanonicalName,$_)
}
get-datastores on host
for each datastore
{
get the first extent of the datastore
for each lun in the first extent
{
$lun = $lunTab[$first_lun]
get-scsilunpath for the lun
display active path -or- set active path to the lunpath we want
}
}
Let me know if that works for you ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
> Let me know if that works for you ?
Holy Carp Batman
Run time went from 30 mins per server down to 1m 25sec per server, so it worked perfectly.
Hash tables (in Powershell) are something I've not used before, but well worth the effort. I think I need to get some training, or a good book.
Thanks very much for your help Luc.
Fyi, I mention some (free) PowerShell learning resources in My PS Library post.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference