Old Stuf‎ > ‎Microsoft‎ > ‎PowerShell‎ > ‎

example of using Jobs in PowerShell 2 for parallel execution

# Loop through the server list
 
Get-Content "ServerList.txt" | %{
 
      # Define what each job does
 
      $ScriptBlock = {
      Test-Path "\\$_\c$\Something"
      Start-Sleep 60
      }
 
  # Execute the jobs in parallel
 
  Start-Job $ScriptBlock
}
 
Get-Job
 
# Wait for it all to complete
 
While (Get-Job -State "Running")
{
  Start-Sleep 10
}
 
# Getting the information back from the jobs
 
Get-Job | Receive-Job
 
 
 
Comments