大家好:这就是我想要做的...
取结果集(例如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命令之间的管道,则会收到意外的 token 错误。
最佳答案
另一种可能性:
$failedcomputers = gc c:\listoffailedcomputers.txt
$CmdParams =
@{
ClassName = 'Win32_Process'
MethodName = 'Create'
Arguments = @{ CommandLine = 'copy \\server\patch\*.* c:\patch\' }
}
Invoke-CimMethod @CmdParams -ComputerName $failedcomputers
那应该对它进行多线程处理,而不必花费大量的远程PS实例来复制文件的开销。
关于variables - 取得一个结果集(例如listofcomputers.txt),并对结果集的每个项目运行一个copy-item命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20298664/