VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot

Script sometimes hungs while executing

Hi,

Below script sometimes hungs while executing, I need to hit enter in the CLI to resume sometimes. Please help, how can I overcome this.

$maxParallel = 2
$sourceesxi = "esx17"
$targetesxi = "esx16"
$vms = get-vmhost $sourceesxi | get-vm *
foreach($vm in $vms){
Move-VM -VM (Get-VM -Name $vm.name) -destination $targetesxi -RunAsync
do
{
sleep 5
} while((Get-Task -Status Running | where{$_.Name -eq 'RelocateVM_Task'}).Count -ge $maxParallel)
}

0 Kudos
3 Replies
LucD
Leadership
Leadership

Can you add the Verbose switch on the PowerCLI cmdlets?
That should perhaps tell you where the script is waiting with a prompt.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot

LucD,

you mean like this ?

$maxParallel = 2
$sourceesxi = "esx17"
$targetesxi = "esx16"
$vms = get-vmhost $sourceesxi | get-vm *
foreach($vm in $vms){
Move-VM -VM (Get-VM -Name $vm.name) -destination $targetesxi -RunAsync -verbose
do
{
sleep 5
} while((Get-Task -Status Running | where{$_.Name -eq 'RelocateVM_Task'}).Count -ge $maxParallel -verbose)
}

0 Kudos
LucD
Leadership
Leadership

Yes, but on all the PowerCLI cmdlets (Get-Task, Get-VM, ...)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos