VMware Cloud Community
poliverson
Contributor
Contributor

PowerCLI and vmotion progress

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

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

poliverson
Contributor
Contributor

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?

Reply
0 Kudos
CRad14
Hot Shot
Hot Shot

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

Conrad www.vnoob.com | @vNoob | If I or anyone else is helpful to you make sure you mark their posts as such! 🙂
Reply
0 Kudos
LucD
Leadership
Leadership

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
winsolo
Enthusiast
Enthusiast

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.

Reply
0 Kudos
LucD
Leadership
Leadership

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


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

Reply
0 Kudos