Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 172599

Powershell Jobs not finishing when using Move-VM

$
0
0

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.Core
     Connect-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:$true
     Write-Host "Im Done Moving"
     Write-Host "Disconnecting from VCenter"
     Disconnect-VIServer * -Confirm:$false -Force:$true
     Write-Host "Disconnected"
$jobSpec = @()
$jobSpec += $jobcmd
$jobSpec += $vCenter
$jobSpec += $acount
$jobSpec += $vipass
$jobSpec += $VMName
$jobSpec += $DestinationDatastore
Start-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


Viewing all articles
Browse latest Browse all 172599

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>