Представляю вам скрипт, который в удобной форме создает BITS job на Powershell и каждые 10 секунд показывает текущий статус передачи. По окончании или при ошибке в лог записывается информация о том, сколько % скопировалось, и каков финальный статус пересылки.
Import-Module BitsTransfer
$file = "file.iso"
$dstpath = "\\server\ISO"
$bitsjob = Start-BitsTransfer -Source D:\Offline_copy\$file -Destination $dstpath -Asynchronous
while( ($bitsjob.JobState.ToString() -eq 'Transferring') -or ($bitsjob.JobState.ToString() -eq 'Connecting') )
{
Write-host $bitsjob.JobState.ToString()
$Proc = ($bitsjob.BytesTransferred / $bitsjob.BytesTotal) * 100
Write-Host $Proc "%"
Sleep 10
}
$date = Get-Date
Switch($bitsjob.JobState)
{
"Transferred" {$date.ToString() + " Succesfully completed transfer of $file at $Proc %. State: " + $bitsjob.JobState.ToString() >> c:\temp\bits_log.txt; Complete-BitsTransfer -BitsJob $bitsjob}
"Error" {$date.ToString() + " An error occured during transfer of $file at $Proc %. State: " + $bitsjob.JobState.ToString() >> c:\temp\bits_log.txt; $bitsjob | Format-List } # List the errors.
default {$date.ToString() + " JobState is not determined of $file at $Proc %. State: " + $bitsjob.JobState.ToString() >> c:\temp\bits_log.txt; Remove-BitsTransfer -BitsJob $bitsjob} # Perform corrective action.
}