2017-11-10 2 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 
関連する問題