6 Replies Latest reply on Jul 9, 2020 9:32 AM by LucD

    PowerCLI and vmotion progress

    poliverson Lurker

      I have a basic script that allowes me to move a vm from one datastore to another which works great. However, I cannot get the script to show progression of the vmotion.

      I am also looking to see if it will alert when the progression gets to 87% with either the powercli screen flashing or an audible alert.

       

      Is this even possible? if so, what is the best way to do it?

       

      My script.

      get-vm -name servername | move-vm -datastore (get-datastore (New Datastore)

       

       

      Thank you

      Patrick

        • 1. Re: PowerCLI and vmotion progress
          LucD Guru
          Community WarriorsvExpertUser Moderators

          I'm not sure if you can intercept the progress of a single cmdlet.

          If you use multiple vMotion in the background (RunAsync), you could use the Write-Progress cmdlet to show the progress bar.

           

          This will produce a "beep" on your station

          $([char]7)

          I don't know about a flashing screen, but you could use some flashing text.

          See Flashing Text in PowerShell?

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          1 person found this helpful
          • 2. Re: PowerCLI and vmotion progress
            poliverson Lurker

            Thanks, that is great help with the beep to get attention. I will give the flashing text link a whirl and see if it help me.

             

            There has to be a way to track progress of a vmotion or Storage vMotion via cli, i cannot get it, can anyone else?

            • 3. Re: PowerCLI and vmotion progress
              CRad14 Hot Shot

              Take a look at the write-progress cmdlet, I believe that is what you are looking for.

              • 4. Re: PowerCLI and vmotion progress
                LucD Guru
                Community WarriorsUser ModeratorsvExpert

                As a matter of fact there is, use the RunAsync parameter on the Move-VM cmdlet.

                This will return a Task object.

                And in the Task object you can find a property called Progress, a number from 1 to 100 that indicates the progress of the task.

                Something like this will loop and report the progress till the task is finished.

                 

                 

                $ds = Get-Datastore -Name MyDS 
                $vm = Get-VM -Name MyVM
                $task
                = Move-VM -VM $vm -Datastore $ds -RunAsync

                while($task.ExtensionData.Info.State -eq "running"){   $task | select @{N="Progress";E={$_.ExtensionData.Info.Progress}}   $task.ExtensionData.UpdateViewData("Info.State","Info.Progress") }

                 

                You can use that number in a Write-Progress cmdlet.

                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                • 5. Re: PowerCLI and vmotion progress
                  winsolo Novice

                  LucD

                   

                  Without the Write-Progress cmdlet, it produces the below output. Should it be used like Write-Progress $task.ExtensionData.Info.Process inside the while loop?

                  With the below script, the VMs did migrate from the source resource pool in cluster-1 to the target resource pool in cluster-2, which is what I needed it to do as it was meant to be a cross-cluster migration. However, the "Progress" hash table displayed the numbers in vertical.

                   

                  $tRP = Get-ResourcePool -Name "ResourcePool-2"

                  $tDS = Get-Datastore -Name "WorkloadDatastore"


                  Get-VM test2, TESTVM88 |

                          ForEach-Object -Process {

                   

                          $task = Move-VM -Destination $tRP -VM $_ -Datastore $tDS -Confirm:$false -RunAsync

                          while($task.ExtensionData.Info.State -eq "running"){

                              $task | select @{N="Progress";E={$_.ExtensionData.Info.Progress}}

                              $task.ExtensionData.UpdateViewData("Info.State","Info.Progress")

                  }}

                   

                  Snag_24a54c1f.png

                   

                  Sorry, I copied the one I used to test with -WhatIf. Just updated the script that migrated the VMs.

                  • 6. Re: PowerCLI and vmotion progress
                    LucD Guru
                    Community WarriorsUser ModeratorsvExpert

                    You are using a Select(-Object) to display the progress.
                    Showing each new Select on a new line is normal behavior.

                    Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz