So let's first talk about creating
background jobs. There were two ways that
we can create background jobs. The first
one is to use the PowerShell command
Start‑Job, which is the most common one
that we've already talked about. And the
second one is to use the & sign at the end
of a command, which will then push it into
a job. The Start‑Job command is defined as
the command to start a PowerShell
background job. It serves no other purpose
apart from starting a job. Now to create a
background job, we can do this by
utilizing Start‑Job. Remember, we talked
about passing the script block, and I'm
going to say go and get the process for
notepad. And this will initiate the
creation of a background job, using the
standard Start‑Job. Now, if we take this
same example and utilize the & property,
then what we end up with is GetProcess
‑Name notepad and then the & operator. So
notice how that changes. The first one we
use Start‑Job, and then we say go and
create it and this is the script block.
The second one, we get rid of the script
block and the start job, and just call the
code that we wish to execute with an & at
the end. A third option here is to utilize
the Invoke‑Command and use the ‑AsJob
parameter. So in this instance, I'm going
to say go and invoke a command on a
specific list of service, I have a text
file with service in, so I'm going to get
the names of those by using Get‑Content.
And then I want to go and get the service
name, so the WinRM, so the Windows Remote
Management one. And then I'm going to
create a job name, throttle it down to a
specific limit, and just send it as a job.
So in actual fact, even though there's two
core ways of creating jobs, Start‑Job and
the & parameter, we can also utilize the
Invoke‑Command and the property for ‑AsJob.