2016-09-01 6 views
1

LAN에 연결된 컴퓨터가 있습니다. 한 대의 PC에서 A 컴퓨터 B에 저장된 배치 파일을 실행하고 싶습니다. A의 모든 리소스를 사용하고 싶지 않습니다.이 배치 파일에는 리소스에 민감한 프로세스가 포함되어 있습니다. 그래서 B의 자원은 오직 사용해야 만합니다. 배치 파일은 B에서 실행해야하지만 A부터 시작해야합니다.다른 컴퓨터에서 컴퓨터의 배치 파일을 실행하는 방법?

+4

가능한 중복 http://stackoverflow.com/questions/15336336/running-batch-file (WMIC는 시작 프로세스의 PID를 반환합니다) -on-remote-computers-using-powershell-2-0) – SomethingDark

답변

0

충분한 권한과 WinRM이 구성되어 있다고 가정합니다.

Invoke-Command -ComputerName 'RemotePCName' -ScriptBlock { 'c:\temp\script.bat' } -Credential $(Get-Credential) 
0

당신은 Invoke-Command을 사용하고 PSSession

을 만들어야합니다 그리고 그것은 다음과 같습니다 당신이 필요로하는 무엇을해야한다고

$session = New-PSSession -ComputerName "ComputerB" 
Invoke-Command -Session $session -ScriptBlock { ./P:\Path\to\bat.bat } 
$session | Remove-Session 

. 당신이 WMIC 또는 Schtasks는 사용할 수있는 배치 파일을 통해

$examplePath = "P:\Path\to" 
$exampleFile = "mySCript.bat" 
$session = New-PSSession -ComputerName "ComputerB" 
$output = Invoke-Command -Session $session -ScriptBlock { ./$args[0] + "\" + $args[1] } -ArgumentList $examplePath, $exampleFile 
$session | Remove-Session 
1

: 당신이 당신의 배치 파일에서 출력이있는 경우 사용할 수있는은 ScriptBlock 내부의 $ 바르 필요한 경우 당신은

$session = New-PSSession -ComputerName "ComputerB" 
$output = Invoke-Command -Session $session -ScriptBlock { ./P:\Path\to\bat.bat } 
$session | Remove-Session 

을 사용할 수 있습니다 :

1) SCHTASKS :

SCHTASKS /s remote_machine /U username /P password /create /tn "On demand demo" /tr "C:\some.bat" /sc ONCE /sd 01/01/1910 /st 00:00 
SCHTASKS /s remote_machine /U username /P password /run /TN "On demand demo" 

2)([PowerShell을 2.0을 사용하여 원격 컴퓨터에서 실행되는 배치 파일]의

WMIC /NODE remote_machine /user user /password password process call create "c:\some.bat","c:\exec_dir" 
+0

나는 SCHTASKS를 시도했다. 하지만이 작업은 14 대의 컴퓨터에서 14 개의 배치 파일을 실행하기 때문에 원하는 작업이 아닙니다. 나는 그들에게 각각의 기계를달라고한다. – Ish