2017-11-10 20 views
0

'computers.txt'에 컴퓨터 목록이 있습니다.목록에서 명령을 실행하고 PsExec 또는 Powershell이이 목록의 다음 항목으로 자동 이동하는 방법

목록의 각 원격 컴퓨터 이름에 .exe를 실행하려고합니다. .exe를 올바르게 설치하는 각 컴퓨터에서 .ps1 스크립트를 실행해야합니다. PsExec에서 각 컴퓨터 이름 사이에 1-2 분 후에 enter를 눌러야합니다. 이렇게하면 원격 컴퓨터 목록을 통해 각 컴퓨터에있는 .exe가 실행됩니다. PowerShell에서 첫 번째 컴퓨터 만 .exe를 실행하고 나머지는 아무것도 수행하지 않습니다.

스크립트가 실행 중일 때 컴퓨터 이름 사이에 Enter 키를 누르지 않고도 목록을 검토 할 수 있습니까? 나는 그것을 모두 자동으로 실행되기를 원한다.

여기 제가 PsExec에서 사용하고있는 것입니다. 여기

psexec -s @C:\App\computers.txt cmd /c "Powershell Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass && PowerShell -noninteractive -file "C:\SpeedInstall.ps1"" 

난 당신이 이전 명령이 다음 단계로 이동하기 전에 완료하는 것이 기다릴 수 있도록 psexec에 함께 /d 스위치를 사용할 수 PowerShell을

$a = Get-Content "C:\App\computers.txt" 
foreach($line in $a) { 
psexec -s \\$line cmd /c "Powershell Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass && PowerShell -noninteractive -file C:\SpeedInstall.ps1" 
} 

답변

0

을 시도하고있는 무슨이다. 명령이 생성 할 수있는 오류 메시지를 볼 수 없지만 목록을 훨씬 빨리 통과 할 수 있다는 단점이 있습니다. 귀하의 명령은 다음과 같이 표시됩니다

$a = Get-Content "C:\App\computers.txt" 
foreach($line in $a) { 
    psexec -s -d \\$line cmd /c "Powershell Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass && PowerShell -noninteractive -file C:\SpeedInstall.ps1" 
} 
0

왜 당신도 psexec를 사용 하시겠습니까? PSRemoting은 어떨까요?

$Computers = Get-Content -Path C:\computers.txt 

foreach ($Computer in $Computers) { 
Copy-Item -Path C:\install.exe -Destination \\$Computer\c$\Windows\Temp\install.exe 
} 

$Script = 
@" 
# Write down your installation script here 
& C:\install.exe /silent 
Set-ItemProperty -Path HKLM:\SOFTWARE\Install -Name Setting -Value 1 -Type DWord 
"@ 

$ScriptBlock = [Scriptblock]::Create($Script) 


$PSSession = New-PSSession -ComputerName $Computers -SessionOption (New-PSSessionOption -NoMachineProfile) 
Invoke-Command -Session $PSSession -ScriptBlock $ScriptBlock