VMware Cloud Community
nmbgdc
Enthusiast
Enthusiast

How to tack the vMotion success or failed using powercli

Hi Guys,

Using the below command and I can migrate the VMs successfully but dont know how to check the status of the vmotion job until it get success.

Here is the command:

$vm=Get-VM -Name myvm-aap

$task = Move-VM -VM $vm -Destination 192.168.100.43 -RunAsync

would appreciate  any help here 

 

 

 

Thanks

 

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

If you run your task in the background (RunAsync), you have to use the Get-Task cmdlet to find the status of that background task.


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast

Hi LucD,

in get-task there might be multiple task in vcenter which one is the specific to current vmotion.

how can I get that ? is there any filter or any id get generated when we initiate the vmotion ?

 

 

Thanks

 

Reply
0 Kudos
LucD
Leadership
Leadership

It depends, there are 2 types of tasks; server-side and client-side.
For a server-side task, the cmdlet where you use the RunAsync switch will return a Task object that contains an Id property.
That Id property can be used on the Get-Task cmdlet with the Id parameter.

For client-side tasks, it's a bit different.
There the background task is running on your station.
The object returned, in that case, will refresh, so it is a matter of monitoring that object in a loop.


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast

Hi LucD,

I am not sure, As i tried as below but it the state it always shows queued, am i missing something in the command,

Get-cluster $cluster_name

Get-VM -Name $testvm_name

Move-VM $testvm_name -Destination $source_host

$VIEvents=get-vm $testvm_name | Get-ViEvent

$VITasks  = $VIEvents | Where Info

$VITasks | Select CreatedTime, FullFormattedMessage

$VITasks.Info | select QueueTime,Name,EntityName,State

 

$task_status=($VITasks.Info | select QueueTime,Name,EntityName,State).state

Write-host $task_status

do{

    # 2

    ($VITasks.Info | select QueueTime,Name,EntityName,State).state

    if($task_status -eq "success"){

        Start-Sleep -Seconds 10

    }

}until($task_status -eq "success")

Write-host VM vMotion success

 

 

Tags (1)
Reply
0 Kudos
LucD
Leadership
Leadership

The objects you retrieved via Get-VIEvent are not updated automatically, you will have to do the Get-VIEvent again inside the While-loop.


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

Reply
0 Kudos