1
00:00:01,140 --> 00:00:05,330
PowerShell via .NET is full of different types of objects.

2
00:00:05,330 --> 00:00:08,900
Now these are some of the most common ones you'll come across. A string

3
00:00:08,900 --> 00:00:14,490
is just text. The int, the i‑n‑t that you see there, is an integer,

4
00:00:14,490 --> 00:00:20,220
although you'll also see sometimes Int32 or Int64, which technically and

5
00:00:20,220 --> 00:00:22,050
in .NET terms is something different.

6
00:00:22,050 --> 00:00:25,500
But for our purposes, we're just going to treat them all as numbers.

7
00:00:25,500 --> 00:00:30,550
DateTime should be self explanatory. And a Boolean is true or false.

8
00:00:30,550 --> 00:00:36,540
In PowerShell, you'll use the Boolean variables $true and $false.

9
00:00:36,540 --> 00:00:40,590
Now how can you discover what type of an object something is or what that

10
00:00:40,590 --> 00:00:43,940
object looks like in terms of its properties and methods?

11
00:00:43,940 --> 00:00:47,320
Well for that, we're going to use the Get‑Member cmdlet.

12
00:00:47,320 --> 00:00:49,430
This cmdlet has an alias of gm,

13
00:00:49,430 --> 00:00:54,040
which you'll use often, and you'll see it a lot in the wild.

14
00:00:54,040 --> 00:00:57,050
Like help and Get‑Command, this is one of the most critical

15
00:00:57,050 --> 00:00:59,430
cmdlets for you to learn and use often.

16
00:00:59,430 --> 00:01:01,880
This is a key discovery command.

17
00:01:01,880 --> 00:01:05,090
One of the reasons that this matters to you is that often

18
00:01:05,090 --> 00:01:08,130
you'll need to discover the rest of the story. When you

19
00:01:08,130 --> 00:01:09,570
run a command in PowerShell,

20
00:01:09,570 --> 00:01:13,740
don't assume that the output that you see is all there is.

21
00:01:13,740 --> 00:01:18,140
PowerShell often has a defined default view of different object types,

22
00:01:18,140 --> 00:01:21,160
which almost never shows you, or almost never shows

23
00:01:21,160 --> 00:01:23,450
you, all of the possible properties.

24
00:01:23,450 --> 00:01:24,950
And in some cases,

25
00:01:24,950 --> 00:01:28,910
PowerShell will use custom names to make the output more meaningful to you.

26
00:01:28,910 --> 00:01:33,140
PowerShell tries to help you and abstract things from you.

27
00:01:33,140 --> 00:01:35,970
Don't assume that what you see is all there is. And this will

28
00:01:35,970 --> 00:01:39,540
become much clearer in the demonstration.

29
00:01:39,540 --> 00:01:44,700
You need to be able to identify other properties because you'll be learning

30
00:01:44,700 --> 00:01:48,330
and using cmdlets that will be able to use any property that you can

31
00:01:48,330 --> 00:01:53,260
identify with Get‑Member. Think of Get‑Member as the authoritative source

32
00:01:53,260 --> 00:01:57,540
for all information relating to an object.

33
00:01:57,540 --> 00:02:01,320
And this can also help you. Not getting a result you expect when you run a

34
00:02:01,320 --> 00:02:06,360
command? Rerun the command and pipe the results to Get‑Member to identify

35
00:02:06,360 --> 00:02:09,180
what's coming out of the pipeline. Or, even better,

36
00:02:09,180 --> 00:02:11,990
drop the last part of your pipeline expression and

37
00:02:11,990 --> 00:02:16,880
pipe to Get‑Member. As you'll see, objects can change in the pipeline,

38
00:02:16,880 --> 00:02:20,540
and you may not be ending up with what you started with.

39
00:02:20,540 --> 00:02:23,510
So by now, it should be pretty clear to you that when you run a

40
00:02:23,510 --> 00:02:27,440
PowerShell command it sends objects down the pipeline.

41
00:02:27,440 --> 00:02:29,960
Although this isn't a locked‑in requirement,

42
00:02:29,960 --> 00:02:34,080
you'll find plenty of code samples in the wild. And in the wild,

43
00:02:34,080 --> 00:02:37,290
I mean that people have published on blogs and in code libraries

44
00:02:37,290 --> 00:02:39,240
and GitHub and that sort of thing.

45
00:02:39,240 --> 00:02:43,800
You'll find plenty of samples where people are using Write‑Host.

46
00:02:43,800 --> 00:02:46,030
And they're using Write‑Host to omit the output,

47
00:02:46,030 --> 00:02:48,450
which, as we saw in the last module,

48
00:02:48,450 --> 00:02:52,400
sends output to the hosting application and not the pipeline.

49
00:02:52,400 --> 00:02:57,040
These types of commands should be considered the exception and not the rule.

50
00:02:57,040 --> 00:03:00,880
You'll also come across commands that don't write an object to the

51
00:03:00,880 --> 00:03:03,550
pipeline because, you know, it just doesn't make sense.

52
00:03:03,550 --> 00:03:05,430
If you kill a process,

53
00:03:05,430 --> 00:03:08,990
the Stop‑Process command, by default, doesn't write anything to

54
00:03:08,990 --> 00:03:12,800
the pipeline. And there's really no reason to. The process is gone

55
00:03:12,800 --> 00:03:14,240
so what are you going to do with it?

56
00:03:14,240 --> 00:03:21,640
Still, if you look at the Stop‑Process help, you'll see a ‑PassThru parameter.

57
00:03:21,640 --> 00:03:27,330
Now if you use this parameter, the cmdlet, in this case Stop‑Process, will

58
00:03:27,330 --> 00:03:30,840
write the object to the pipeline that it was working with.

59
00:03:30,840 --> 00:03:34,600
This might be useful if you are using Stop‑Process in a

60
00:03:34,600 --> 00:03:38,370
situation where you want to run the command and then send it

61
00:03:38,370 --> 00:03:40,200
to something to create an audit trail.

62
00:03:40,200 --> 00:03:45,180
Whenever you see ‑PassThru in the help for a command, that is

63
00:03:45,180 --> 00:03:48,150
your clue that the command does not write anything to the

64
00:03:48,150 --> 00:03:51,850
pipeline so you can't pipe anything from that command to

65
00:03:51,850 --> 00:03:54,940
something else unless you use ‑PassThru.

66
00:03:54,940 --> 00:03:59,940
Now of course what makes PowerShell easy is that you can join commands together.

67
00:03:59,940 --> 00:04:04,440
Some commands are designed to accept or consume objects.

68
00:04:04,440 --> 00:04:08,340
These commands may be designed to take an entire object,

69
00:04:08,340 --> 00:04:12,040
or they may use properties of an incoming object.

70
00:04:12,040 --> 00:04:15,580
Very often when you see a Get‑Command there'll be one or more

71
00:04:15,580 --> 00:04:18,440
corresponding commands to do something with it.

72
00:04:18,440 --> 00:04:21,320
So, Get‑Service has related commands to let you set,

73
00:04:21,320 --> 00:04:24,340
stop, start, and restart a service.

74
00:04:24,340 --> 00:04:28,740
You can get a bunch of services that meet some criteria and

75
00:04:28,740 --> 00:04:32,020
then pipe them to something like Restart‑Service. Again,

76
00:04:32,020 --> 00:04:33,500
there's no cryptic scripting.

77
00:04:33,500 --> 00:04:36,370
It's a relatively simple PowerShell expression.

78
00:04:36,370 --> 00:04:41,440
I always try to get people to think about this idea of managing at scale.

79
00:04:41,440 --> 00:04:43,900
And this may make more sense when you get to scripting.

80
00:04:43,900 --> 00:04:46,640
If you can do something for one object,

81
00:04:46,640 --> 00:04:51,640
you can probably do the same thing to 100 or 1000 objects.

82
00:04:51,640 --> 00:04:56,140
Don't think about doing something or writing a command to do one thing.

83
00:04:56,140 --> 00:05:05,000
Think about how would I write it to do something for all things or 100 things. The PowerShell pipeline is what makes this possible.

