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 developers 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 v3 defines three broad but distinct types of jobs: those based on the Remoting architecture covered in the previous chapter (also known as background jobs), those based on WMI and CIM, and those based on a new “scheduled job” architecture. 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.

11.1. Remoting-based jobs

There are two ways to start jobs that utilize the Remoting system: Start-Job and Invoke-Command. Start-Job is designed to start a job that runs entirely on your local computer and technically doesn’t use the Remoting subsystem to function because it doesn’t use remote machines. Invoke-Command starts a job that’s tracked on your local machine but that sends commands to remote computers for execution there. Invoke-Command is a great way to coordinate running a command on a bunch of remote computers.

Note

If you use Invoke-Command locally and use the -Computername or -AsJob parameter, PowerShell will use Remoting to the local computer, so it must be enabled.

11.1.1. Starting jobs

11.2. WMI jobs

11.3. Scheduled jobs

11.4. Job processes

11.5. Summary