WEBVTT

00:00:00.000 --> 00:00:01.500
So let's get straight into it,

00:00:01.510 --> 00:00:05.930
and we'll talk about using the Invoke‑Command for querying.

00:00:07.470 --> 00:00:12.420
So the Invoke‑Command executes commands on local and remote computers.

00:00:13.010 --> 00:00:15.650
It returns all output from the commands,

00:00:15.660 --> 00:00:16.910
including any errors,

00:00:16.910 --> 00:00:21.680
and it also supports executing what's called a script block as a command,

00:00:21.680 --> 00:00:25.090
a script block being some other piece of PowerShell

00:00:25.090 --> 00:00:26.570
code that we need to execute.

00:00:27.300 --> 00:00:28.580
So what does this look like?

00:00:29.070 --> 00:00:31.500
Well, if I want to retrieve running services locally,

00:00:31.700 --> 00:00:36.990
I can simply say Invoke‑Command, and there we see the ScriptBlock property,

00:00:37.000 --> 00:00:41.960
which is in the squirrely brackets, which we're using Get‑Service.

00:00:41.990 --> 00:00:44.710
So that will simply return all of the services.

00:00:45.000 --> 00:00:49.820
If I extend this a little bit, I can use the similar syntax we used before,

00:00:49.820 --> 00:00:54.170
which was Get‑Service with a Where‑Object to get only the running options.

00:00:54.720 --> 00:00:58.360
If I wanted to run the same on a remote server,

00:00:58.370 --> 00:01:04.080
I can simply add ‑ComputerName WIN10, and then either of those options

00:01:04.080 --> 00:01:07.190
would work when trying to run it against a remote machine.
