我欣然承认我对 PowerShell 的流利程度并不高。我设法找到了一个我需要做的例子,并主要根据我的需要对其进行了调整。代码如下。我想知道的是,是否可以进行任何更改,以便如果我要在 PowerShell 的不同实例中调用脚本,那么所有传输都会同时运行。
$Job = Read-Host "Enter a name for this transfer job."
$Destination = Read-Host "Enter the full UNC path for the destination."
$Source = Read-Host "Enter the full path for the file to be transferred."
import-module bitstransfer
Start-BitsTransfer -Destination $Destination -Source $Source -Asynchronous -DisplayName $Job -Authentication NTLM -Credential (Get-Credential) -Priority Normal -RetryTimeout 60 -RetryInterval 120 -TransferType Upload
$bits = Get-BitsTransfer -Name $Job
while ($bits.JobState -eq "Transferring" -or $bits.JobState -eq "TransientError" -or $bits.JobState -eq "Connecting" -or $bits.jobstate -eq "Error" -and $pct -ne 100){
if ($bits.jobstate -eq "Error"){
Resume-BitsTransfer -BitsJob $bits
}
$pct = ($bits.BytesTransferred / $bits.BytesTotal)*100
Cls
Write-Host "Percent complete: $pct"
Start-Sleep 5}'