
誰か私のコードを見て、invoke-command を使用するときに、なぜ私の PC がまだ仲介者として使用されているのか教えてもらえますか?
自分の PC を仲介者として使用せずに、転送先のコンピューターに直接転送するようにしています。
Invoke-Command -ComputerName $DestinationComputer -Credential $creds -Authentication Credssp -ScriptBlock {
robocopy \\$($args[0])\C$\usmt \\$($args[1])\C$\usmt /E /COPY:DATOU /E /ZB /mt:32 /r:5 /w:0
}-ArgumentList $SourceComputer,$DestinationComputer -ErrorAction Inquire
答え1
ROBOCOPY
はい、そのコンピュータ上で のプロセスを実行しています$DestinationComputer
。ただし、とInvoke-Command
を待機するマシン上では依然として が実行されています。stdout
stderr
ドキュメントから
Invoke-Commandコマンドレットは、ローカルまたはリモートコンピュータでコマンドを実行し、エラーを含むコマンドからのすべての出力を返します。
したがって、この動作はコードで想定されています
Invoke-Command -ComputerName $DestinationComputer -Credential $creds -Authentication
Credssp -ScriptBlock {
robocopy \\$($args[0])\C$\usmt \\$($args[1])\C$\usmt /E /COPY:DATOU /E /ZB /mt:32
/r:5 /w:0
}-ArgumentList $SourceComputer,$DestinationComputer -ErrorAction Inquire
必要なのは、オプションを渡すことですInDisconnectedSession
。これによりInvoke-Command
、接続、cmd の実行、切断がすぐに行われます。ドキュメントから再度引用します。
切断されたセッションを作成するには、Invoke-Command コマンドレットの InDisconnectedSession パラメーターを使用します。このコマンドはセッションを作成し、コマンドを開始し、コマンドが出力を返す前に直ちに切断します。
これがあなたが求めているものです。
乾杯。