Powershell 在远程服务器上复制文件';s位置子目录

Powershell 在远程服务器上复制文件';s位置子目录,powershell,loops,foreach,Powershell,Loops,Foreach,我已经创建了一个脚本来复制远程服务器上的本地文件 远程位置是C:\past,本地文件需要从C:\past复制到所有子目录中。 (即c:\pass\1、c:\pass\2、c:\pass3、c:\pass\4等) 低于误差 enter Get-ChildItem : Cannot find path 'C:\past' because it does not exist. At line:3 char:14 + $folders = Get-ChildItem "C:\past" -Dire

我已经创建了一个脚本来复制远程服务器上的本地文件 远程位置是C:\past,本地文件需要从C:\past复制到所有子目录中。 (即c:\pass\1、c:\pass\2、c:\pass3、c:\pass\4等)

低于误差

enter Get-ChildItem : Cannot find path 'C:\past' because it does not 
exist.
At line:3 char:14
+   $folders = Get-ChildItem "C:\past" -Directory
+              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (C:\past:String) [Get-
ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : 
PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommandcode 
here
使用全名而不是名称

这没有意义,它是从本地计算机获取目录

foreach ($computer in $computers)
{
 $folders = Get-ChildItem "C:\past" -Directory 
}
复制项没有-ComputerName参数

copy-item _path $PathFrom -ComputerName $computers
检查示例

既然你说你可以通过UNC路径到达它,这应该满足你的要求

$PathFrom = "C:\ISO\ncis.exe" 
$computers="192.168.42.117"
foreach ($computer in $computers){
     Get-ChildItem "\\$computer\C$\past" -Directory | %{ Copy-Item -path $PathFrom -Destination $_.Fullname }
}

是的,这是我卡住的地方。C:\past是远程目录(即192.168.42.117上的)是服务器还是网络资源,您可以通过执行\\192.168.42.117\。。。如果没有,那么远程服务器是否已打开PS远程处理?您收到的错误是因为当前您没有在远程服务器上查看脚本,而是在本地服务器上运行脚本。错误的意思正是它所说的….找不到文件夹C:\past是的,我可以通过\\192.168.42.117\访问它。您是否尝试使用\\192.168.42.117\C$\past….进行复制。。。。。你能到达那个位置吗?手动点击文件浏览器\\192.168.42.117\c$\pass,它可以工作,但是,不知道如何使用scriptGetting Down执行此操作错误
复制项:输入对象无法绑定到命令的任何参数,因为命令不接受管道输入,或者输入及其属性与接受管道输入的任何参数都不匹配。
谢谢@ArcSet,它可以工作。它是否覆盖了现有的文件?
copy-item _path $PathFrom -ComputerName $computers
$PathFrom = "C:\ISO\ncis.exe" 
$computers="192.168.42.117"
foreach ($computer in $computers){
     Get-ChildItem "\\$computer\C$\past" -Directory | %{ Copy-Item -path $PathFrom -Destination $_.Fullname }
}