Problems with 'Wait-mission' and 'CloneVM_Task' in the script of vm - backup.ps1

Hey all,.

I hope you can help me with something. An environment that I help standing needs a systematic clone (copy) large number of virtual machines from a data store to another for customer test scenarios.

Not being is not a type of programmer, I found a script that looks like it fits the Bill here: http://www.mbnbusiness.co.uk/blog/2010/08/updated-powercli-vmware-vm-backup-script-v2-0/

However, when I run the script, I have two errors that seem to keep me from moving.

(1) the first issue seems to revolve around the wait-job command.

Waiting-Task: cannot bind parameter 'task '. Cannot convert the 'work-task-425″ type value 'VMware.Vim.ManagedObjectReference' to type 'VMware.VimAutomation.Sdk.Types.V1.Task'. C:\vmbackup\vm-backup.ps1:275 tank: 34
+ Wait-Task < < < < $task
+ CategoryInfo: InvalidArgument: (:)) [waiting-Task], ParameterBindingException)
+ FullyQualifiedErrorId: CannotConvertArgumentNoMessage, VMware.VimAutomation.ViCore.Cmdlets.Commands

(2) the second issue is the creation of clones themselves. I see no error thrown in the PowerCLI console while the creation of clone, but I see errors indicating in vCenter:

Clone the virtual machine

VCE-bvm-30_sub

Has specified parameter was not correct.  Home

Any help you could provide would be most appreciated. I have attached the script, the input file and the error of console output.

Thank you!

Hi Aaron,

(1) the problem here is that the variable $task contains an object of type ManagedObjectReference. It is essentially the task ID, while the Wait-job cmdlet waits for an object of type Task. What you need to get the object by its task ID and pass it to the Wait-job cmdlet. Put this befeore the line of the "Wait-Task $task" line: "$task = Get-job | "where {$_.id - eq $task}.

(2) you do not specify a valid host in the $cloneSpec that you pass to the CloneVM_Task operation (' $vmView.CloneVM_Task ($cloneFolder, $cloneName, $cloneSpec) "). Set the it to the host where you want to place the cloned VM (by setting the property $cloneSpec.Location.Host). The host parameter can be set in certain situations, you need to decide based on the configuration you. Here is the description of the host of the VI QAnywhere parameter:

The target host for the virtual machine. If not specified,

  • If the resource pool is not specified, current host is used.
  • If the resource pool is specified and the target pool represents a stand-alone host, the host is used.
  • If the resource pool is specified and the target pool represents a DRS cluster enabled, a host selected by DRS is used.
  • If the resource pool is specified and that the pool of the target represents an active without DRS cluster, an InvalidArgument exception thrown.

I hope this helps.

Kind regards

-Angel

Tags: VMware

Similar Questions

Maybe you are looking for