简体   繁体   中英

How to Delay Complete-BitsTransfer until Transfer Complete?

The following bits transfer starts a bunch of bits jobs, which work perfectly when I manually complete the transfer later: Get-BitsTransfer | Complete-BitsTransfer 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM