Okay, so let's have a look at how we wait
for the remote background jobs to
complete. Think about that. We may have
1,000 servers that we wish to execute a
command on and we want to be able to wait
for those to complete. Now, in this
example here, we're still using the same
option where we're creating a new
non‑interactive PowerShell session, but
I'm using three machines, Computer1, 2,
and 3. Then I'm going to invoke a command
into those non‑interactive PowerShell
sessions. And then what I'm going to do at
that point is I'm going to pass a
ScriptBlock and you'll see there is a
nested script block here, so we have a
ScriptBlock to start a job and then a
ScriptBlock for that Start‑Job. So you can
see the kind of nest in the structure.
Then underneath that, I have a done
variable where I'm now saying invoke the
command to the session, go and pass a
command which will be Wait‑Job, and then
retrieve the name of the job that I
created in the first invoke. So if we're
creating them remotely, we can actually
kind of structure and nest the ScriptBlock
options to retrieve the values that we need.