Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 246801

Re: Powershell Jobs not finishing when using Move-VM

$
0
0

That didnt seem to work either. I did figure out a workaround though, here is the interjob code. Its not perfect, but it should get me by. I am curious as to why the powershell jobs hang on some tasks like move-vm though.

 

 

$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 -Id $in[4]
Write-Host "Getting Datastore Object"
$JobDatastoreObject = Get-Datastore -Id $in[5]
Write-Host "Moving VM"
$task = Move-VM -VM $JobVMObject -Datastore $JobDatastoreObject -RunAsync
$RunTask = $True
Write-Host "Waiting On Job To Finish"
sleep 5
while ($RunTask){
$Tasks = Get-Task | where {($_.Name -eq "RelocateVM_Task") -and ($_.ObjectId -eq $JobVMObject.ID)}
If ($Tasks -ne $null){
     foreach ($Task in $Tasks){
         if (($task.state -eq "Success") -or ($task.state -eq "Error")){
              $RunTask = $False
              Break
                  }
                 else {
                              $Time = Get-Date
                              Write-Host "Still Waiting On Job To Finish - $Time"
                          }
                     }
               }
               Else {
                    Write-Host "Cannot find task with VM ID and a name of RelocateVM_Task"
                        break
                }
           start-Sleep 5
       }

 

     Write-Host "Im Done Moving"

 

     Write-Host "Disconnecting from VCenter"

     Disconnect-VIServer * -Confirm:$false -Force:$true

     Write-Host "Disconnected"


Viewing all articles
Browse latest Browse all 246801

Trending Articles



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