PowerShell for Windows Admins

Feb 19 2014   12:15PM GMT

Oh–so that’s what its for

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: