VMware Cloud Community
feixfb
Contributor
Contributor
Jump to solution

Track Status of move-vm Task fails

Hey,

i am working on a script which check the status of the datastore befor a snapshot of a vm is taken. If the free space on the ds in not enough it will move the vm to a other ds which will meet the needed free space.

The script works well so far. But sometimes the move process take a time and i want to get some Info about the state of completion of the task...I tryed this..

<code snip>

if ($targetDS) {

            write-host "Die VM" $vm "wird nun von" $aktivDS.Name "nach" $targetDS.Name "verschoben" -ForegroundColor DarkGreen

            $moveVMJob = Move-VM -VM $vm -Datastore $targetDS.Name -RunAsync -Confirm:$false

           

            while ('Success', 'Error' -notcontains $moveVMJob.State) {

                $moveVMJob

                Write-Output $moveVMJob.PercentComplete

                sleep 5

           }    

</code snip>

<output snip>

Die VM snaptest2 wird nun von testserver_02-000C2 nach testserver_03-00088 verschoben

Name            State   % Complete Start Time Finish Time

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

RelocateVM_Task Running          0 11:22:28

0

RelocateVM_Task Running          0 11:22:28

0

RelocateVM_Task Running          0 11:22:28

0

RelocateVM_Task Running          0 11:22:28

0

RelocateVM_Task Running          0 11:22:28

0

RelocateVM_Task Running          0 11:22:28

0

RelocateVM_Task Running          0 11:22:28

<output snip>

What do i wrong?

Thanks

Feix

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You need to refresh the object that reflects the task.

Inside the While-loop, and after the sleep, do

$moveVMJob = Get-Task -Id $moveVMJob.Id


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

You need to refresh the object that reflects the task.

Inside the While-loop, and after the sleep, do

$moveVMJob = Get-Task -Id $moveVMJob.Id


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

0 Kudos
feixfb
Contributor
Contributor
Jump to solution

Works like a charm.

Thank you LucD

0 Kudos