VMware Cloud Community
RoyalFlash
Enthusiast
Enthusiast
Jump to solution

Wait-Task Problem

Hi,

I have a script that moves a VM to another Cluster.

$MoveVMTask = Move-VM -vm "VMName" -Destination (Get-Cluster -name NewCluster)

Wait-Task -Task $MoveVMTask

I get a:

Wait-Task : Cannot bind parameter 'Task'. Cannot convert the "VMNAME" value of type "VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl" to type "VMware.VimAutomation.Sdk.Types.V1.Task".

How to use Wait-Task properly

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Yes, that helps sometimes as well.

And no, no clue why that would happen.


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

View solution in original post

5 Replies
LucD
Leadership
Leadership
Jump to solution

The Wait-Task only works for tasks that run in the background, and that is done through the RunAsync switch.

$MoveVMTask = Move-VM -vm "VMName" -Destination (Get-Cluster -Name NewCluster) -RunAsync

Wait-Task -Task $MoveVMTask


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

0 Kudos
RoyalFlash
Enthusiast
Enthusiast
Jump to solution

Hi LucD

thanks for your fast reply.

I tried -RunAsync but now i get "Wait-Task : Operation is not valid due to the current state of the object."

But the VM is moving....

​Something is still wrong??

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If the vMotion is actually do, then it looks like an issue I have seen before.

Try this procedure Re: Eh? Move-VM Generates Error Messages, But Works Anyway!?!? 


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

0 Kudos
RoyalFlash
Enthusiast
Enthusiast
Jump to solution

Now its working! Thank you! 🙂

"I found that closing the current powershell session and opening a new one seems to resolve the issue. Running version 6.0."

But i really do not understand why????

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, that helps sometimes as well.

And no, no clue why that would happen.


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