
누군가 내 코드를 보고 호출 명령을 사용할 때 내 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 cmdlet은 로컬 또는 원격 컴퓨터에서 명령을 실행하고 오류를 포함하여 명령의 모든 출력을 반환합니다.
따라서 귀하의 코드에서는 이러한 동작이 예상됩니다.
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 cmdlet의 InDisconnectedSession 매개 변수를 사용합니다. 세션을 생성하고 명령을 시작한 다음 명령이 출력을 반환하기 전에 즉시 연결을 끊습니다.
이것이 당신이 요구하는 것입니다.
건배.