I'm trying to get a script to work that will svmotion all machines listed in folder to a new datastore cluster and new host (which are in a separate cluster) once the migration is completed, power on the vm.
The error I'm getting
Wait-Task : Cannot validate argument on parameter 'Task'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At C:\temp\svmotion\final.ps1:11 char:18
+ Wait-Task -Task <<<< $task
+ CategoryInfo : InvalidData: (:) [Wait-Task], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.WaitTask
Here is my script
#Import Plugins and Connect to vCenter
Add-PSSnapin VMware.VimAutomation.Core
$creds = Get-Credential
$viserver = Read-Host "vCenter Server:"
Connect-VIServer -Server $viserver -Credential $creds
# Get a List of VM's from the relocation folder
$vmlist = get-vm -location "relocateme"
#Stoage vMotion each VM in selected cluster in a staged fashion
foreach($vm in $vmlist)
{
Write-Host Relocating..."$vm"
$task = Get-VM -Name $vm.Name | Move-VM -Datastore "Test Datastore" -Destination VMHOST1.NET
Wait-Task -task $task
Start-VM $vm.name
}
Once the script has exited get-vm -location "relocateme" shows the VM listed, however write-host $vmlist and write-host $vm both contain no data.
If I do write-host $task it is also blank. What am I missing?
The names of our VM's are long and contain special characters. Could this be the problem?. An example machine name is "AA-BB-CC-DD (Test Machine for Migrations)[T][+]" (excluding the commas).
I'm using Powercli 5.1
Any help would be greatly appreciated.