This is a script block from a larger script I am using to feed it parameters. The background job never finishes if I leave off the -runasync flag. The task completes fine in VC, but I don't see any of the write-hosts in the job output after the Move-Vm line. I have tried this in both powershell v2 and v3 with powercli 5.0 and 5.1 . Any ideas?
$vCenter = "VCenterName"
$DestinationDatastore = "DestinationDatastoreName"$VMName = "VMName"$Account = "Username"$VIPass = "Password"# Define Job Parameters$jobcmd ={$in = $input.'<>4__this'.read();Add-PSSnapin VMware.VimAutomation.CoreConnect-VIServer $in[1] -User $in[2] -Password $in[3]Write-Host "Getting VM Object"$JobVMObject = get-vm -Name $in[4]Write-Host "Getting Datastore Object"$JobDatastoreObject = Get-Datastore -name $in[5]Write-Host "Moving VM"Move-VM -VM $JobVMObject -Datastore $JobDatastoreObject -Verbose:$trueWrite-Host "Im Done Moving"Write-Host "Disconnecting from VCenter"Disconnect-VIServer * -Confirm:$false -Force:$trueWrite-Host "Disconnected"}$jobSpec = @()$jobSpec += $jobcmd$jobSpec += $vCenter$jobSpec += $acount$jobSpec += $vipass$jobSpec += $VMName$jobSpec += $DestinationDatastoreStart-Job -InputObject $jobSpec -ScriptBlock $jobSpec[0]
Wait until the task in VC completes, then run this command, and you should see that the job doesnt progress past the move-vm command.
Get-Job | Receive-Job -Keep