2
作爲項目要求的一部分,我正在準備一個腳本來從本地計算機中的文件複製到遠程服務器(用戶名和密碼)將文件複製到遠程計算機
我曾與下面的方法試了文件27 KB和50 MB大小
i。使用ReadallBytes和WriteAllBytes 這是工作的小文件,27 KB,其中爲50 MB其採取100%的CPU佔用太多的時間
$myfile = [System.IO.File]::ReadAllBytes("C:\Temp\test\a.txt")
$Stat = $null
$session=$null
$session = New-PSSession -computerName $server -credential $user
$Stat = Invoke-Command -Session $session -ArgumentList $myfile -Scriptblock {[System.IO.File]::WriteAllBytes("C:\temp\a.txt", $args)} -ErrorAction Stop
II。我試圖複製,項目複製,但問題是目標目錄沒有安裝尖
$Stat = Invoke-Command -ComputerName $server -ScriptBlock { Copy-Item -Path "C:\Temp\test\a.txt" -Destination "C:\temp\a.txt" -Recurse -Force -PassThru -Verbose } -Credential $user
這兩種方式來襲,請提出任何其他的方式來實現,而不安裝目標文件夾
考慮PowerShell中內置的文件傳輸命令:'拷貝Item'或'啓動BitsTransfer'。如果您真的需要速度/發現自己處理更大的文件,請考慮第三方解決方案,例如TeraCopy(http://www.codesector.com/teracopy);儘管在你提到的情況下,這不是必需的。 – JohnLBevan