
The State will change to Completed when the job has finished and the HasMoreData value will indicate if there is output.


In the example output below, notice that the job is still running.Īfter the job has been kicked off, you can check on the status of the job by running the Get-Job command, noting the State and HasMoreData values. This indicates that there is output to be retrieved from the job. You can check on the status of a job by running Get-Job, the status is in the “State” column, which will show if the command is Running, Completed, or Failed. These jobs do all of their processing in the background and store the output until you receive them. Submitting a large number of background commands could be resource intensive.īelow are two different ways to do a WMI Query as a job: Get-WMIObject Win32_OperatingSystem -AsJob Keep in mind that there are limits to everything so keep your machine’s resource consumption in mind as you test this concept out. This also means that you can submit multiple jobs in the background and continue processing without waiting for each job to complete. PowerShell Cmdlets sometimes include the “ -AsJob” parameter that will allow the command to submitted in the background, releasing the console to be used for other commands. Alternatively, you can use the Start-Job CmdLet to run commands as Jobs. I did some research on multi-threading with VBScript and kept getting results that referred to PowerShell “jobs”, which gave me the motivation to start learning PowerShell.įor those of you who come from a Unix or Linux background, jobs will be a familiar concept since you can background any command by placing an “ &” at the end of the command. The only bad part about this script was that it took days to run against the machines, processing each one sequentially in a For loop before moving on to the next.

Each machine needed to have the exact same set of commands executed on it, a new file copied and service restarted, to fix them so I created a quick VBScript to connect to each machine and perform the fix actions. Then fate threw me a curve ball when I was presented with a task to fix over 9,000 workstations that had lost their “parent” antivirus server. I have to be honest, back in 2010 I was firmly entrenched in VBScript and had no interest in learning anything new. Stay tuned in the upcoming weeks for some amazing regular content. Hello everyone! Doctor Scripto is elated to present some more great content from Joel Vickery, PFE, today he discusses using jobs in PowerShell.
