1
00:00:01,040 --> 00:00:05,130
Welcome back! In this module, we'll take a look at how PowerShell works

2
00:00:05,130 --> 00:00:08,840
with objects in the pipeline and why it matters to you.

3
00:00:08,840 --> 00:00:12,350
Understanding this paradigm is crucial to your success in using

4
00:00:12,350 --> 00:00:14,840
and eventually scripting with PowerShell.

5
00:00:14,840 --> 00:00:17,000
This is something that can be difficult for PowerShell

6
00:00:17,000 --> 00:00:19,850
beginners to truly grasp, but once they do,

7
00:00:19,850 --> 00:00:22,240
a lot of things begin to make sense.

8
00:00:22,240 --> 00:00:26,470
PowerShell is all about working with objects in a pipeline.

9
00:00:26,470 --> 00:00:30,240
You're not parsing a bunch of text to get results to look the way you want them.

10
00:00:30,240 --> 00:00:33,310
You're telling PowerShell, get me these things,

11
00:00:33,310 --> 00:00:36,870
do something with them, and then finally, show me the results.

12
00:00:36,870 --> 00:00:41,640
PowerShell is an interactive management tool that takes advantage of this

13
00:00:41,640 --> 00:00:45,380
pipeline process. And it doesn't matter if you're running PowerShell

14
00:00:45,380 --> 00:00:48,620
interactively, at a console prompt as we're doing in this course,

15
00:00:48,620 --> 00:00:51,540
or running PowerShell in a script or function,

16
00:00:51,540 --> 00:00:55,040
it's still all about objects in the pipeline.

17
00:00:55,040 --> 00:00:59,130
Traditional and legacy tools tend to be text based. Even something

18
00:00:59,130 --> 00:01:02,990
like VBScript that sort of gives you objects, you still often

19
00:01:02,990 --> 00:01:06,210
needed to treat those results like text in order to get the

20
00:01:06,210 --> 00:01:08,640
desired output. With these tools,

21
00:01:08,640 --> 00:01:11,210
and you can think of command line tools like netstat or

22
00:01:11,210 --> 00:01:14,530
Linux commands like ps, they give you text,

23
00:01:14,530 --> 00:01:18,040
which you often have to parse to get exactly what you want.

24
00:01:18,040 --> 00:01:20,360
Now, this is not necessarily a bad thing.

25
00:01:20,360 --> 00:01:24,650
Linux has terrific tools for this task like grep and awk,

26
00:01:24,650 --> 00:01:27,540
assuming you know how to use them.

27
00:01:27,540 --> 00:01:29,610
But Windows is not text based, right?

28
00:01:29,610 --> 00:01:33,890
It's based on objects, and to a great extent this means .NET.

29
00:01:33,890 --> 00:01:37,600
So it makes sense that a management tool for Windows would

30
00:01:37,600 --> 00:01:40,640
be based on .NET and be object centered.

31
00:01:40,640 --> 00:01:40,860
Now,

32
00:01:40,860 --> 00:01:44,790
because of this dependency on .NET, Windows PowerShell

33
00:01:44,790 --> 00:01:46,950
remained a proprietary language.

34
00:01:46,950 --> 00:01:51,580
But, once Microsoft decided to make .NET Core available on

35
00:01:51,580 --> 00:01:55,260
non‑Windows platforms and made it an open source project,

36
00:01:55,260 --> 00:01:58,340
PowerShell really wasn't that far behind.

37
00:01:58,340 --> 00:02:00,140
And really, that's where we are today.

38
00:02:00,140 --> 00:02:02,510
The version of PowerShell that runs on Windows,

39
00:02:02,510 --> 00:02:07,100
Linux, and Mac is relying on .NET Core. And even on non‑Windows

40
00:02:07,100 --> 00:02:11,340
platforms, the concept is still objects in the pipeline.

41
00:02:11,340 --> 00:02:13,500
When you run a PowerShell command,

42
00:02:13,500 --> 00:02:16,170
it's typically creating and, in some situations,

43
00:02:16,170 --> 00:02:17,650
consuming objects.

44
00:02:17,650 --> 00:02:19,720
This is really what the pipeline is all about.

45
00:02:19,720 --> 00:02:23,520
You get a bunch of things in PowerShell and pass them to

46
00:02:23,520 --> 00:02:25,930
another command and then on to another.

47
00:02:25,930 --> 00:02:30,820
Where it gets tricky is that you may start with one type of object

48
00:02:30,820 --> 00:02:33,040
and end up with something completely different,

49
00:02:33,040 --> 00:02:37,140
depending on what the cmdlet you are piping to is designed to do.

50
00:02:37,140 --> 00:02:39,770
Now this is actually a good thing because it means you can

51
00:02:39,770 --> 00:02:43,360
perform some pretty complex commands from a PowerShell prompt

52
00:02:43,360 --> 00:02:46,240
with no scripting and minimal effort.

53
00:02:46,240 --> 00:02:48,270
At the end of your pipeline expression,

54
00:02:48,270 --> 00:02:52,450
PowerShell displays whatever is left in the pipeline to your screen.

55
00:02:52,450 --> 00:02:58,140
But up until that point, it's really all about objects in the pipeline.

56
00:02:58,140 --> 00:03:02,640
Of course, it helps to understand what an object means in this context.

57
00:03:02,640 --> 00:03:05,540
You don't have to be a developer to use PowerShell,

58
00:03:05,540 --> 00:03:09,250
but you should understand a few basic concepts.

59
00:03:09,250 --> 00:03:10,500
Now for our purposes,

60
00:03:10,500 --> 00:03:14,360
an object is a software representation of some thing

61
00:03:14,360 --> 00:03:16,320
that you want to manage or work with.

62
00:03:16,320 --> 00:03:21,080
It could be a process, service, mailbox, or vegetable. Objects have

63
00:03:21,080 --> 00:03:26,000
properties, which are ways to describe it. Thinking about our vegetable, it

64
00:03:26,000 --> 00:03:29,140
might have a property to control or show the color.

65
00:03:29,140 --> 00:03:31,220
Maybe there's a property that gives you the number of

66
00:03:31,220 --> 00:03:34,990
objects or number of vegetables.

67
00:03:34,990 --> 00:03:38,740
The other common part of an object is this idea of methods.

68
00:03:38,740 --> 00:03:44,140
These are actions that you can do to an object or maybe that the object does.

69
00:03:44,140 --> 00:03:46,870
Continuing with our vegetable object idea,

70
00:03:46,870 --> 00:03:50,940
it might have methods of, say, peel or chop.

71
00:03:50,940 --> 00:03:56,190
Now don't worry, most of the time you'll use cmdlets to manipulate objects,

72
00:03:56,190 --> 00:04:00,380
even though under the hood these cmdlets are working with the

73
00:04:00,380 --> 00:04:03,240
properties and methods of the corresponding objects.

74
00:04:03,240 --> 00:04:06,670
Now you can too, and sometimes you really have no choice.

75
00:04:06,670 --> 00:04:11,020
But for now, as a beginner, you should be able to use,

76
00:04:11,020 --> 00:04:14,140
and you should stick with using PowerShell cmdlets.

77
00:04:14,140 --> 00:04:16,040
There are other elements to an object,

78
00:04:16,040 --> 00:04:26,000
but properties and methods are the primary ones that we'll be focusing on. These are referred to generically, or collectively, as an object's members.

