1

みなさんこんにちは: これは私がやろうとしていることです.... 結果セット(例: 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 コマンドの間のパイプを削除すると、予期しないトークン エラーが発生します。

4

3 に答える 3

5

コンピューター名をコマンドレットにパイプするだけで、コマンドレットがその使用方法を理解することを期待することはできません。パラメータCopy-Itemすら含まれていません。-ComputerName2つのアプローチを試すことができます

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\"
}
于 2013-11-30T10:36:08.080 に答える
2

別の可能性:

$failedcomputers = gc c:\listoffailedcomputers.txt

$CmdParams = 
@{ 
   ClassName  = 'Win32_Process'
   MethodName = 'Create'
   Arguments  = @{ CommandLine = 'copy \\server\patch\*.* c:\patch\' }
 }


Invoke-CimMethod @CmdParams -ComputerName $failedcomputers

ファイルのコピーを行うためだけに多数のリモート PS インスタンスをスピンアップするオーバーヘッドなしで、マルチスレッド化する必要があります。

于 2013-11-30T14:58:02.687 に答える
1

Get-Help Copy-Item -fullISE でを見ると、パイプラインで何を受け入れることができるかがわかります。Copy-ItemProperty へのパスを含む文字列をパイプできます。このインスタンスでは実際にホスト名をパイプしているため、そのエラーが発生しています。

これを試して:

    copy-item \\server\patch\*.* -destination \\$failedcomputer\C$\patch
于 2013-11-30T10:35:44.720 に答える