Chapter 15. Multitasking with background jobs

Everyone’s always telling you to multitask, right? Why shouldn’t PowerShell help you with that by doing more than one thing at a time? It turns out that PowerShell can do exactly that, particularly for longer-running tasks that might involve multiple target computers. Make sure you’ve read chapters 13 and 14 before you dive into this chapter, because we’ll be taking those remoting and WMI concepts a step further.

15.1. Making PowerShell do multiple things at the same time

You should think of PowerShell as a single-threaded application, meaning that it can do only one thing at once. You type a command, you hit Enter, and the shell waits for that command to execute. You can’t run a second command until the first command finishes.

But with its background jobs functionality, PowerShell has the ability to move a command onto a separate background thread (a separate, background PowerShell process). That enables the command to run in the background, as you continue to use the shell for another task. But you have to make that decision before running the command; after you press Enter, you can’t decide to move a long-running command into the background.

After commands are in the background, PowerShell provides mechanisms to check on their status, retrieve any results, and so forth.

15.2. Synchronous vs. asynchronous

15.3. Creating a local job

15.4. WMI, as a job

15.5. Remoting, as a job

15.6. Getting job results

15.7. Working with child jobs

15.8. Commands for managing jobs

15.9. Scheduled jobs

15.10. Common points of confusion

15.11. Lab

15.12. Lab answers

sitemap