我試圖將幾個檔案復制到我的遠程框中,但我看到路徑格式不正確的問題,有人可以查一下嗎?
for($hostname in Get-Content C:\folder1\machine.txt){
Copy-Item -Path "C:\folder1\ramen-0.1-web-1.3.6.jar" -Destination "\\hostname\C:\folder1\folder2\" -Recurse -Force
}
錯誤訊息是:復制專案:不支持給定路徑的格式。
uj5u.com熱心網友回復:
您缺少的“$”符號。您正在使用'c:'作為目標路徑的一部分。
for($hostname in Get-Content C:\folder1\machine.txt){
Copy-Item -Path "C:\folder1\ramen-0.1-web-1.3.6.jar" -Destination "\\hostname\C$\folder1\folder2\" -Recurse -Force
}
uj5u.com熱心網友回復:
如果啟用了 powershell 遠程,這是另一種方式(foreach not for)(-recurse 對檔案沒有意義):-ToSession 不能是陣列。
$list = Get-Content C:\folder1\machine.txt
$sessions = new-pssession $list
foreach($session in $sessions){
Copy C:\folder1\ramen-0.1-web-1.3.6.jar C:\folder1\folder2 -ToSession $session -For
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/380577.html
標籤:电源外壳 powershell-2.0 powershell-3.0 powershell-4.0 powershell-remoting
