So why should we use PowerShell jobs?
Well, the PowerShell background jobs allow
you to move singular tasks into batches of
tasks for easier management. This allows
us to increase performance because jobs
execute separately, allowing for better
performance. We can execute multiple
tasks, which means it's not going to lock
the PowerShell console while the tasks are
being executed, and we could also schedule
the tasks also to run at specific times.
We can also use this for long running
tasks. So for example, maybe you want to
execute something that's going to query a
database or some other set of files and
there's a lot of them, you can use a
PowerShell job for that long running task.
We can also use them for remoting. So, for
example, if I wanted to use a PowerShell
job that did something on multiple servers
in my estate, then I can use PowerShell
remoting tasks inside a background job for
that one. An important thing to understand
is that scheduled jobs, or what used to be
available within previous versions of
PowerShell, are not supported within
PowerShell 7. You can still create tasks
that will execute these commands, but the
old way of doing it is no longer
supported. Now let's talk about some kind
of scenarios. So why would you use
PowerShell jobs? Well, for example, you
might be in a large organization where
there are hundreds of servers to manage
and maybe you need to query all of them
for the amount of RAM on the servers. A
second option could be maybe you're using
on‑premises and cloud services, and maybe
you need to update specific details within
Azure Active Directory from another
on‑premises application. So both instances
are kind of long running jobs that are
suited very well to a background job, so
we can kick those off and just leave them
to it, and they will complete when they are ready.