Okay, so now that we've created jobs and
we can remove them, we now need to
understand how we can wait for background
jobs to actually complete. And, of course,
that would be useful to know, because we
need to know that the jobs have completed
so that we can execute other things
afterwards. So the command we'll use is
Wait‑Job. What this one does is suppresses
the command prompt until one or all of the
PowerShell background jobs running in the
session are complete. That's what it's
designed for. If I want to utilize Wait, I
can say Get‑Job | Wait‑Job. And that will
actually tell me to wait for that specific
job to complete and suppress the command
prompt. I could then wait for several jobs
by ID to finish. So I could say Wait‑Job,
specific ones that are executing by ID,
and then it will suppress again and wait.
I could also then wait for any of the
Invoke‑Command options to run. So if I'm
doing Invoke‑Command into a new PowerShell
session, as we did previously with the
Get‑Process ‑AsJob, I could then say get
that job and then just wait. So we have a
way of kind of waiting or at least forcing
the console to wait for a job to complete.
This is helpful if you're trying to review what's going on in that job itself.