Chapter 11. Background jobs and scheduling
This chapter covers
- Creating jobs
- Retrieving job results
- Managing the job queue
- Using scheduled jobs
In PowerShell, jobs are one of the many extension points provided to the shell for you to build on. Jobs allow you to run tasks asynchronously—you get the prompt back to continue working while PowerShell runs the job in the background. PowerShell v4 (beginning in v3) defines four broad but distinct types of jobs: those based on the Remoting architecture covered in the previous chapter (also known as background jobs)—though they don’t use PowerShell Remoting directly—those based on WMI and CIM, and those based on a new “scheduled job” architecture.
Note
The CIM cmdlets themselves don’t have an –AsJob parameter you have to use Start-Job or Invoke-Command to wrap the command as a job. If you create a CDXML module using the cmdlet-over-objects technology (see chapter 39) you’ll automatically get an –AsJob parameter added to your cmdlets.
PowerShell workflows can also be run as jobs, as you’ll learn in chapter 23. Each of these jobs works slightly differently, but all of them represent the same essential thing: a unit of work that’s run in the background.