VM Junkie

May 7, 2009

When Powershell is a little bit TOO fast…

Filed under: esx, powershell, vmware — ermac318 @ 9:49 am

Last night I was doing a bunch of migrations on a severely overworked vCenter box, moving a bunch of VMs from an old cluster to a new one. I tried using it to do a bunch of cold migrations, i.e.:
$vmlist | Move-VM -Destination $desthost

Unfortunately, what happened was performing this on 40 powered off VMs initiates all 40 tasks at one. This really makes vCenter unhappy and it just kind of sits there staring at these 40 tasks “In Progress” and freezes up for a good 3 or 4 minutes. In one instance this actually failed and said “unable to communicate with remote host” and failed all the tasks after only 2 or 3 completed.

Unfortunately, rather than serializing these operations, it was just doing them in parallel. So I wondered, how could I serialize these and give the poor vCenter server a break?

$vmlist | % { Move-VM -VM $_ -destination $desthost
Start-Sleep -Seconds 5 }

Tada! By wrapping it in a foreach loop and adding a sleep, this made life much easier for my poor vCenter box. That’ll teach me to use the built-in SQL Express database…



  1. Were you using vCenter 4? I had something similar today with Remove-VM. For me I didn’t need to add a sleep. Still this seems to be something new.

    Comment by Carter Shanklin — May 8, 2009 @ 6:18 am

  2. Nope, this was on vCenter 2.5 Update 4.
    Still, this brings up the question – why are these asynchronous tasks? Many tasks (like Move-VM on a running VM, start-VM, etc) are Synchronous tasks, but some (like Move-VM on a powered-off VM, remove-vm) are asynchronous.
    Might it be better to make all Powershell commands synchronous unless you add the -RunAsync command? That would have also solved my problem – then the default behavior wouldn’t have generated 40 tasks simultaneously.

    Comment by ermac318 — May 8, 2009 @ 11:16 am

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Blog at WordPress.com.

%d bloggers like this: