I’ve never really understood the logic behind the Wait-Job cmdlet. The idea of PowerShell Jobs is to kick of tasks that grind away in the background and you get the prompt back so you can keep on working. Wait-Job stops the prompt being returned until one or more jobs have finished.
It clicked this morning – I need to run some tasks in parallel and decided that a number of jobs was the best way (I looked at workflow but there are some complications such that I didn’t pursue that route). The only complication with using Jobs is that you don’t know when they finish (unless you check with Get-Job) and I needed a number of Jobs to finish before starting the last job in the series – this is a data dependency issue that I can’t avoid.
Wait-Job is the answer. Start my first set of jobs. Use:
Get-Jobs | Wait-Job
which means nothing else is done until all my jobs finish and then start the last job.
As I’m going to be running this through a scheduled task I don’t care about the prompt being frozen.
Nice to finally find a use for a cmdlet I’ve ignored since it appeared.