2016-11-02 3 views
0

내가하려는 것은 원격 컴퓨터의 배치 파일을 작업으로 실행하는 것입니다. 배치 파일은 C:\Users\temp 폴더 안에있는 모든 컴퓨터에 있습니다. 여기 있습니다. 코드
$batFile = "test.bat" foreach($m in $machine) { Invoke-Command -ComputerName $m -ScriptBlock{param($batFile) & cmd.exe /c "C:\Users\temp\$batFile"} -Authentication negotiate -Credential $cred -ArgumentList $batFile -AsJob }powershell을 배경 작업으로 사용하여 원격 컴퓨터에서 배치 파일 실행

하지만 파이프 라인의 요소에 '&'후

표현가 계속이 유효하지 않습니다 객체를 생성했다. 이 명령 이름, 스크립트 블록 또는 내가 성공하지뿐만은 ScriptBlock 내부 $using:batFile를 사용하여 시도한하는 CommandInfo 객체

발생해야합니다. 누구든지 내가 뭘 잘못하고 있다고 제안 할 수 있습니까? 나는, 그에 대한 추적을 할

Invoke-Command -ComputerName $m -ScriptBlock{param($batFile) Trace-Command NativeCommandParameterBinder -Expression { & cmd.exe /c "C:\Users\temp\$batFile"}} -Authentication negotiate -Credential $cred -ArgumentList $batFile -AsJob 

을 PowerShell을 버전 4

+0

나는 그것을 재현 할 수 없다, 내 loc에 .bat를 호출하는 나를 위해 작동한다. "$ bat"} --ArgumentList 't.bat'-AsJob' 그리고'& $ bat'와 함께 작동합니다. 'cmd $ bat' 변형을 사용합니다. '-ScriptBlock {param ($ batFile) cmd.exe/c "C : \ Users \ temp \ $ batFile"}'을'&'없이 쓰면 어떨까요? – TessellatingHeckler

+0

이 문제는 나를 미치게합니다. invoke-command를 사용하는 다른 방법이 있습니까? 시작 작업을 수행 할 때 문제가 보이지 않지만 scriptblock 안에 computername을 전달할 때 배치 파일은 computername을 배치 파일의 매개 변수로 전달할 것이라고 생각합니다. Start-Job -ScriptBlock {cd "C : \ Users \ temp "; cmd.exe/c; C : \ Users \ temp \ test.bat "-ComputerName $ machineName} –

+0

-ScriptBlock {param ($ batFile) cmd.exe/c"C : \ Users \ temp \ $ batFile " } '없이 &? '&'뒤에 오는 표현은 무엇입니까? – TessellatingHeckler

답변

0

을 사용하고 &

invoke-Expression "cmd.exe /c 'C:\Users\temp\$batFile'" 

감사 대신 해결 방법으로 Invoke-Expression를 사용하여 시도하고

Kvprasoon

관련 문제