Powershell Monitor Job Status

This is the framework for a basic monitoring of a PowerShell job.

The basic steps are to store the current jobs in to a variable named $jobs. Loop through the variable and increment $jobcount if the state of the job does not equal “Completed”. The script keeps looping until $jobcount is 0.

Lines 11 and 12 are merely demonstrative. You could put anything here you want…

do
{
   $jobcount = 0
   $jobs = Get-Job
   foreach ($job in $jobs)
   {
    if ($job.state -ne "Completed"){
    $jobcount++
    }
   }
   Write-Verbose "Active jobs: $jobcount"
   Start-Sleep -Seconds 5
}
until ($jobcount -lt 1)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s