VMware Cloud Community
sjesse
Leadership
Leadership
Jump to solution

Check for active vmotions

Hi

I know how to find old vmotions, is there a way to find active vmotions, I'm trying to write a script to rebalance or cluster between two ucs domains using drs rules, but I only want to do 8 at a time and wait for any active vmotions to finish.

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this.

It will stay in the While-loop while any vMotions are queued or running.

$taskMgr = Get-View TaskManager

while (Get-View -Id $Taskmgr.RecentTask |

   where { 'Running', 'Queued' -contains $_.Info.State -and

   'VirtualMachine.relocate', 'Drm.ExecuteVMotionLRO' -contains $_.Info.DescriptionId })

{

  sleep 1

   $taskMgr.UpdateViewData()

}

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

You could do something like this.

It will stay in the While-loop while any vMotions are queued or running.

$taskMgr = Get-View TaskManager

while (Get-View -Id $Taskmgr.RecentTask |

   where { 'Running', 'Queued' -contains $_.Info.State -and

   'VirtualMachine.relocate', 'Drm.ExecuteVMotionLRO' -contains $_.Info.DescriptionId })

{

  sleep 1

   $taskMgr.UpdateViewData()

}

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

Reply
0 Kudos
sjesse
Leadership
Leadership
Jump to solution

Thank LucD​ thats working well and it moving along quite quickly compared to my other tests. For anyone that sees this the full script I used was

$vms=Import-csv -UseCulture domain1vms.csv

foreach($vm in $vms)

{

    $vm=Get-VM $vm.VMS

    Set-DrsClusterGroup -DrsClusterGroup "UCS Domain 2 VMS" -VM $vm.Name -Add

    Set-DrsClusterGroup -DrsClusterGroup "UCS Domain 1 VMS" -VM $vm.Name -Remove

    $taskMgr = Get-View TaskManager

    while (Get-View -Id $Taskmgr.RecentTask |where { 'Running', 'Queued' -contains $_.Info.State -and 'VirtualMachine.relocate', 'Drm.ExecuteVMotionLRO' -contains $_.Info.DescriptionId })

    {

        sleep 1

        $taskMgr.UpdateViewData()

    }

}

Reply
0 Kudos