Представим себе, что нам необходимо параллельно запустить несколько копирований через BITS. Это можно сделать в помощью Powershell Workflow. Параллельно создаются BITS Job, для каждой из которых каждые 15 секунд выводится статус копирования. Требуется Powershell версии 5.1 или выше.
По умолчанию Workflow может выполнять только 5 параллельных процессов.
$computers = 'server1','server2'
workflow parallelcopy {
param ([string[]]$computername)
ForEach -Parallel ($computer in $computername) {
InlineScript {
$Filename = "Deploy.rar"
$Destination = "\\$using:computer\ISO"
$source = "D:\Offline_copy\FU1703"
$bitsjob = Start-BitsTransfer -Source $source\$Filename -Destination $Destination -Asynchronous
"BITS Transfer started for $using:computer."
while( ($bitsjob.JobState.ToString() -eq 'Transferring') -or ($bitsjob.JobState.ToString() -eq 'Connecting') )
{
Write-host "Job State at $using:computer is: " + $bitsjob.JobState.ToString()
$Proc = ($bitsjob.BytesTransferred / $bitsjob.BytesTotal) * 100
Write-Host "Progress at $using:computer is: $Proc %"
Sleep 15
}
$date = Get-Date
Switch($bitsjob.JobState)
{
"Transferred" {$date.ToString() + " Succesfully completed transfer at $Proc %. State: " + $bitsjob.JobState.ToString(); Complete-BitsTransfer -BitsJob $bitsjob}
"Error" {$date.ToString() + " An error occured during transfer at $Proc %. State: " + $bitsjob.JobState.ToString(); $bitsjob | Format-List } # List the errors.
default {$date.ToString() + " JobState is not determined at $Proc %. State: " + $bitsjob.JobState.ToString()} # Perform corrective action.
}
}
}
}
Import-Module BitsTransfer
parallelcopy -computername $computers