
원격 컴퓨터에 소프트웨어를 설치하기 위한 PowerShell 스크립트가 있습니다.
현재까지 다음 코드를 성공적으로 사용했습니다.
$prog = "ping"
$arg = "localhost"
$computername = "MACHINE01"
invoke-command -computername $computername {param($p,$a)& $p $a} -ArgumentList $prog,$arg
이제 MSI를 설치해야 합니다. 'msiexec /ic:\file.msi /passive'.
MSIEXEC에서 'MSIEXEC' 이후의 모든 항목을 매개변수로 처리하도록 할 수 없습니다. 대신 PowerShell은 이를 하나의 큰 명령으로 실행하려고 시도합니다. 나는 주로 문자 그대로의 인용문을 배치하는 것과 관련된 많은 것을 시도했지만 이것이 작동하도록 할 수는 없습니다.
이제 '-ArgumentList' 매개변수가 있는 'Start-Process'를 선호하여 호출 연산자(&)를 포기했습니다. 이제 MSI가 올바르게 실행됩니다. 엄청난!
invoke-command -computername $computername {param($p,$a) start-process $p -argumentlist $a -nonewwindow -wait -redirectstandardoutput c:\output.txt; get-content c:\output.txt} -ArgumentList $prog,$arg
'Start-Process'의 문제점은 'Invoke-Command'를 사용하여 원격으로 실행할 때 콘솔 출력을 생성하지 않는다는 것입니다. 출력을 파일로 리디렉션한 다음 파일을 읽어야 했습니다. 더 좋은 방법이 있나요?
답변1
나는 그것을 tee-object cmdlet에 파이핑한 다음 필요하다면 거기에 파일을 저장하려고 합니다(파일 출력을 $null로 보내는 것이 작동할지 모르겠습니다. 안타깝지만 이것은 Linux가 아니므로 /로 보낼 수 있습니다). dev/null, 그러나 나는 빗나갔다)
이것은 tee-object cmdlet입니다.http://technet.microsoft.com/en-us/library/ee177014.aspx
invoke-command -computername $computername {param($p,$a) start-process $p -argumentlist $a -nonewwindow -wait | tee-object -file c:\output.txt} -ArgumentList $prog,$arg
그건 테스트되지 않은 코드야, 그러나 그것은 일반적으로 당신이 원하는 것입니다.
invoke-command -computername $computername {param($p,$a) start-process $p -argumentlist $a -nonewwindow -wait | tee-object -file $null} -ArgumentList $prog,$arg
잘 작동할 수도 있습니다.