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
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
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?
Take a look at the write-progress cmdlet, I believe that is what you are looking for.
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
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.
$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")
}}
Sorry, I copied the one I used to test with -WhatIf. Just updated the script that migrated the VMs.
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