【问题标题】:powershell copy files into remote machine issue using Copy_Item cmdletpowershell 使用 Copy_Item cmdlet 将文件复制到远程计算机问题
【发布时间】:2022-01-16 18:52:48
【问题描述】:

我试图将几个文件复制到我的远程盒子中,但我看到路径格式不正确的问题,有人可以检查一下吗?

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

}

错误信息是: Copy-Item : 不支持给定路径的格式。

【问题讨论】:

    标签: powershell powershell-2.0 powershell-3.0 powershell-4.0 powershell-remoting


    【解决方案1】:

    您丢失的 '$' 符号。您正在使用 '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
    
    }
    

    【讨论】:

      【解决方案2】:

      如果启用了 powershell 远程,这是另一种方式(foreach 不是 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
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-07-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多