Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a script but it takes hours to execute. What do i need to do to make this run in parallel?

 $servers = Get-Content -Path c:\Scripts\MyServerList.txt
foreach ($Server in $servers)
 Write-Output $Server;
 Get-EventLog -LogName System -EntryType Error -ComputerName $Server | Measure-Object
share|improve this question
In parallel with what? – John Gardeniers Sep 14 '11 at 11:41
"Myserverlist.txt" contains a list of servers that I want checked. Powershell runs the command on each server in order they are listed in the text file. I was wondering what can be done in order for all the servers to have that command run at once instead of one-at-a-time. – Jake Sep 14 '11 at 11:44

Referencing this Stack Overflow post.

Running your construct on 3 servers of mine took 2:23.

Running the below script took 2:07. Not a lot of savings, but running on a larger number may get you more time savings. You can also mess around with how you output at the end I think.

# Loop through the server list
Get-Content "C:\scripts\Servers.txt"| %{

  # Define what each job does

  $ScriptBlock = {
    Write-Output $Server;
 Get-EventLog -LogName System -EntryType Error -ComputerName $Server | Measure-Object|Out-String -Stream


  # Execute the jobs in parallel

  Start-Job $ScriptBlock -ArgumentList $_

# Wait for it all to complete

While (Get-Job -State "Running")
  Start-Sleep 1

# Getting the information back from the jobs

Get-Job | Receive-Job|Write-Host
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.