PowerShell Background Jobs

By: Cam Wohlfeil
Published: 2018-02-07 0000 EST
Category: Programming
Tags: powershell

PowerShell background jobs are a simple and powerful tool and can be used with almost any Powershell or regular cmd commands. The most important cmdlets for using background jobs are Start-Job, Get-Job, and Remove-Job. Jobs have to be removed after completion or they will remain in a completed state.

Start-Job -ScriptBlock {Repair-Volume $drive -SpotFix}
Get-Job | where {$_.State -eq "Completed"} | Remove-Job

Note: Background jobs can be used with almost all commands by just adding -AsJob!

Invoke-Command -ComputerName (Get-Content servers.txt) -ScriptBlock {Get-Service winrm} -JobName "WinRM" -ThrottleLimit 16 -AsJob

More Info: