0

The following bits transfer starts a bunch of bits jobs, which work perfectly when I manually complete the transfer later: Get-BitsTransfer | Complete-BitsTransfer

My attempt to script a delay before complete is not working. The While is not processed, or perhaps it's processed before the transfer jobs even start.

loop starts many jobs...
    $job = Start-BitsTransfer -Source $fileUrl -Destination $fileDest -Asynchronous
...end loop

While ($job.JobState -eq "Transferring") {
    Sleep -Seconds 1
}

Get-BitsTransfer | Complete-BitsTransfer

Any suggestion how to permit -Asynchronous jobs a chance to load before executing complete?

After I added a 1-second delay before the wait, the script above waits. Seems hacky.

Volkmar Rigo
  • 1,158
  • 18
  • 32
STWilson
  • 1,538
  • 2
  • 16
  • 26
  • 2
    You are probably waiting in While loop only for "last package" of bittransfers created by previous loop. Could you post code of the loop which creates BitTransfers? – cezarypiatek Dec 17 '16 at 08:49

1 Answers1

0

cezarypiatek deserves this answer:

Problem is the While loop checking only the last package. Code corrected to:

$job - @()
loop starts many jobs...
    $job += Start-BitsTransfer -Source $fileUrl -Destination $fileDest -Asynchronous
...end loop

While ($job | Where-Object{$job.JobState -eq "Transferring"}) {
    Sleep -Seconds 1
}

Get-BitsTransfer | Complete-BitsTransfer
STWilson
  • 1,538
  • 2
  • 16
  • 26