2 Replies Latest reply on Aug 12, 2019 8:55 AM by sjesse

    Check for active vmotions

    sjesse Master
    vExpertUser Moderators

      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.

        • 1. Re: Check for active vmotions
          LucD Guru
          vExpertUser ModeratorsCommunity Warriors

          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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Check for active vmotions
            sjesse Master
            vExpertUser Moderators

            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()

                }

             

             

            }