Created
April 1, 2014 00:40
-
-
Save AdilHindistan/8b07998c565a41f0e684 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How many jobs we should run simultaneously | |
$maxConcurrentJobs = 3; | |
# Read the input and queue it up | |
$jobInput = get-content .\input.txt | |
$queue = [System.Collections.Queue]::Synchronized( (New-Object System.Collections.Queue) ) | |
foreach($item in $jobInput) | |
{ | |
$queue.Enqueue($item) | |
} | |
# Function that pops input off the queue and starts a job with it | |
function RunJobFromQueue | |
{ | |
if( $queue.Count -gt 0) | |
{ | |
$j = Start-Job -ScriptBlock {param($x); Get-WinEvent -LogName $x} -ArgumentList $queue.Dequeue() | |
Register-ObjectEvent -InputObject $j -EventName StateChanged -Action { RunJobFromQueue; Unregister-Event $eventsubscriber.SourceIdentifier; Remove-Job $eventsubscriber.SourceIdentifier } | Out-Null | |
} | |
} | |
# Start up to the max number of concurrent jobs | |
# Each job will take care of running the rest | |
for( $i = 0; $i -lt $maxConcurrentJobs; $i++ ) | |
{ | |
RunJobFromQueue | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment