大家好:这就是我要做的......拿一个结果集(例如listoffailedcomputers.txt)并对结果集中的每个项目运行一个复制命令.逻辑是在failedlistofcomputers.txt中的所有计算机上运行复制命令,以便最终结果将该文件夹本地复制到该列表上的所有计算机上.我可以通过在所有这些计算机上使用远程控制台来实现这一点,但这样做效率不高.谢谢.
这是我到目前为止写的代码.......
$failedcomputers = gc c:\listoffailedcomputers.txt foreach ($failedcomputer in $failedcomputers) { $failedcomputer | copy-item \\server\patch\*.* -destination c:\patch\ }
这就是我得到的错误......
Copy-Item : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. At copypatchtofailedcomputers.ps + $failedcomputer | copy-item <<<< \\server\patch\ -destination c:\patch\ + CategoryInfo : InvalidArgument: (mycomputername:PSObject) [Copy- Item], ParameterBindingException + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Command s.CopyItemCommand
如果我在我的语句中删除$ failedcomputer变量和copy-item命令之间的管道,我将收到意外的令牌错误.
您不能将计算机名管道传输到任何cmdlet中,并期望它了解如何使用它.Copy-Item
甚至没有包含-ComputerName
参数.你可以尝试两种方法
您可以copy-item
在每台计算机上远程执行,如下所示:
$failedcomputers = gc c:\listoffailedcomputers.txt foreach ($failedcomputer in $failedcomputers) { Invoke-Command -ComputerName $failedcomputer -ScriptBlock { copy-item \\server\patch\*.* -destination c:\patch\ } }
或者,如果您可以从计算机访问所有远程计算机,则可以尝试直接从一个网络共享复制到另一个网络共享(目标计算机),如下所示:
$failedcomputers = gc c:\listoffailedcomputers.txt foreach ($failedcomputer in $failedcomputers) { copy-item \\server\patch\*.* -destination "\\$failedcomputer\c$\patch\" }