1
00:00:01,140 --> 00:00:02,770
Hello, and welcome back.

2
00:00:02,770 --> 00:00:04,740
We're in the middle of learning about how to get the

3
00:00:04,740 --> 00:00:07,070
most of the PowerShell help system.

4
00:00:07,070 --> 00:00:08,240
In the last module,

5
00:00:08,240 --> 00:00:12,340
I should you had update help and start getting help from PowerShell.

6
00:00:12,340 --> 00:00:16,000
Next, I want to teach you how to interpret what you find.

7
00:00:16,000 --> 00:00:19,790
The better that you can read help, the more you can get out of it,

8
00:00:19,790 --> 00:00:22,730
and the easier I think it will be to figure out why a command

9
00:00:22,730 --> 00:00:24,940
doesn't work the way you think it should.

10
00:00:24,940 --> 00:00:26,480
Alright, so let's get to it.

11
00:00:26,480 --> 00:00:29,770
Here's the first part of help for the Get‑Service command.

12
00:00:29,770 --> 00:00:34,390
The NAME, SYNOPSIS, and DESCRIPTION should all be self evident.

13
00:00:34,390 --> 00:00:38,400
I want to focus on helping you decipher all this stuff under SYNTAX.

14
00:00:38,400 --> 00:00:41,180
These are the different ways that you can use the command.

15
00:00:41,180 --> 00:00:44,190
The first thing I want to point out is that based on the help,

16
00:00:44,190 --> 00:00:48,260
I can see that there are three different way to use Get‑Service.

17
00:00:48,260 --> 00:00:52,830
Under SYNTAX , you can see three different groupings of parameters.

18
00:00:52,830 --> 00:00:55,840
These are referred to as parameter sets.

19
00:00:55,840 --> 00:00:59,800
Each set shows the name of the command, Get‑Service,

20
00:00:59,800 --> 00:01:02,430
followed by a collection of parameters.

21
00:01:02,430 --> 00:01:04,220
Now these collections are unique.

22
00:01:04,220 --> 00:01:07,540
Although some parameters can appear in multiple parameter sets,

23
00:01:07,540 --> 00:01:10,620
there's usually something in each set that makes it unique.

24
00:01:10,620 --> 00:01:14,190
You can't mix and match parameters, that's very important.

25
00:01:14,190 --> 00:01:18,400
If you try to run Get‑Service using both ‑Name and ‑DisplayName,

26
00:01:18,400 --> 00:01:20,830
you'll get an error saying that PowerShell can't

27
00:01:20,830 --> 00:01:23,250
figure out which parameter set to use.

28
00:01:23,250 --> 00:01:27,140
All parameters in PowerShell start with a dash.

29
00:01:27,140 --> 00:01:32,110
So we have ‑DependentServices and ‑DisplayName.

30
00:01:32,110 --> 00:01:34,670
Following the parameter name is an indication of

31
00:01:34,670 --> 00:01:37,190
what type of valve you you can use.

32
00:01:37,190 --> 00:01:40,310
Now everything in PowerShell is a type of object.

33
00:01:40,310 --> 00:01:41,480
After a DisplayName,

34
00:01:41,480 --> 00:01:45,670
you can see that PowerShell is telling you that it can accept strings.

35
00:01:45,670 --> 00:01:49,590
Now a string is just a fancy way of saying text.

36
00:01:49,590 --> 00:01:53,820
The double square brackets after the type name indicate that the

37
00:01:53,820 --> 00:01:57,250
parameter will take a collection or group of values.

38
00:01:57,250 --> 00:02:00,030
Typically, these are separated by commas.

39
00:02:00,030 --> 00:02:01,220
Based on the help,

40
00:02:01,220 --> 00:02:05,520
‑DisplayName will let me specify a group of service display names,

41
00:02:05,520 --> 00:02:07,860
again separated by commas.

42
00:02:07,860 --> 00:02:10,710
Another type of parameter is a switch.

43
00:02:10,710 --> 00:02:13,570
Look at that ‑RequiredServices.

44
00:02:13,570 --> 00:02:15,740
There's no value after it.

45
00:02:15,740 --> 00:02:19,960
It switches like an on/off switch, or you can think true/false.

46
00:02:19,960 --> 00:02:21,910
If you use the parameter name,

47
00:02:21,910 --> 00:02:25,070
then the command's code will handle the rest of the operation,

48
00:02:25,070 --> 00:02:27,450
you don't have to do anything else.

49
00:02:27,450 --> 00:02:30,070
Now I'll tell you this because eventually you're going to

50
00:02:30,070 --> 00:02:33,670
come across commands that have parameters that feel and look

51
00:02:33,670 --> 00:02:36,490
like they should be switches, but for some reason,

52
00:02:36,490 --> 00:02:38,990
the person or team that wrote the command,

53
00:02:38,990 --> 00:02:41,530
they want you to specify true or false.

54
00:02:41,530 --> 00:02:44,610
The new ADUser command is a good example.

55
00:02:44,610 --> 00:02:49,540
It has a parameter called ‑Enabled, which you can use to enable the account.

56
00:02:49,540 --> 00:02:52,070
Now I think it should be a switch,

57
00:02:52,070 --> 00:02:56,320
and all I should need to do is just run ‑Enabled,

58
00:02:56,320 --> 00:02:59,590
but nope, I have to type ‑Enabled $true.

59
00:02:59,590 --> 00:03:06,450
When you look at the help, you'll see that the parameter wants a boolean value.

60
00:03:06,450 --> 00:03:09,910
That's why you need to read the help and not make any assumptions.

61
00:03:09,910 --> 00:03:14,170
The last thing to cover is the square brackets surrounding parameters.

62
00:03:14,170 --> 00:03:17,200
This indicates the item in brackets is optional.

63
00:03:17,200 --> 00:03:21,090
You don't have to use ‑DependentServices or ‑Include,

64
00:03:21,090 --> 00:03:23,240
but if you want to use ‑DisplayName,

65
00:03:23,240 --> 00:03:28,640
you have to type the parameter name because it is not in brackets.

66
00:03:28,640 --> 00:03:31,890
Now compare that to the ‑Name parameter.

67
00:03:31,890 --> 00:03:36,320
The entire parameter is optional, and if you want to use the parameter,

68
00:03:36,320 --> 00:03:38,890
you don't need to type ‑Name.

69
00:03:38,890 --> 00:03:41,880
The parameter name is optional.

70
00:03:41,880 --> 00:03:43,940
This is referred to as a positional parameter,

71
00:03:43,940 --> 00:03:45,880
and I'll come back to this in a few minutes.

72
00:03:45,880 --> 00:03:48,010
In meantime, here's another example.

73
00:03:48,010 --> 00:03:50,630
Here you can see the help for Get‑Process,

74
00:03:50,630 --> 00:03:54,780
and you'll notice that the ‑Id parameter is not in brackets,

75
00:03:54,780 --> 00:03:58,050
meaning you have to type the name if you want to use it,

76
00:03:58,050 --> 00:04:01,200
and it can accept a collection of Int32 types,

77
00:04:01,200 --> 00:04:02,830
or integers.

78
00:04:02,830 --> 00:04:04,060
And how do I know that?

79
00:04:04,060 --> 00:04:05,770
See that double square brackets?

80
00:04:05,770 --> 00:04:07,440
That's how we know.

81
00:04:07,440 --> 00:04:11,960
‑IncludeUserName is a switch and doesn't need any values.

82
00:04:11,960 --> 00:04:13,690
So how about a pop quiz.

83
00:04:13,690 --> 00:04:14,960
Looking at that help,

84
00:04:14,960 --> 00:04:18,660
do you think that you can use ‑IncludeUserName and

85
00:04:18,660 --> 00:04:23,040
‑FileVersionInfo in the same command?

86
00:04:23,040 --> 00:04:24,970
No, of course not.

87
00:04:24,970 --> 00:04:28,580
There is no parameter set that includes both parameters.

88
00:04:28,580 --> 00:04:31,210
If you tried that, you'd see the error message,

89
00:04:31,210 --> 00:04:34,880
Parameter set cannot be resolved using the specified name parameters.

90
00:04:34,880 --> 00:04:38,790
One or more parameters issued cannot be used together or an

91
00:04:38,790 --> 00:04:41,420
insufficient number of parameters were provided.

92
00:04:41,420 --> 00:04:43,510
So PowerShell tells you very clearly, hey,

93
00:04:43,510 --> 00:04:45,830
I have no idea what you're trying to do because you're

94
00:04:45,830 --> 00:04:47,650
trying to mix and match parameters.

95
00:04:47,650 --> 00:04:52,100
By the way, the common parameters that you see there,

96
00:04:52,100 --> 00:04:54,840
and we saw it with the help for Get‑Services as well,

97
00:04:54,840 --> 00:05:00,010
that's really a placeholder for a set of parameters that all cmdlets have.

98
00:05:00,010 --> 00:05:03,940
These are parameters like ‑Verbose or ‑ErrorActionPreference.

99
00:05:03,940 --> 00:05:07,500
You will learn more about those as you learn more about PowerShell.

100
00:05:07,500 --> 00:05:10,210
We really won't get into them in this course.

101
00:05:10,210 --> 00:05:13,030
Or if you want a little exercise, to try this.

102
00:05:13,030 --> 00:05:16,830
See if you can find a help topic that explains how to use them,

103
00:05:16,830 --> 00:05:18,400
or what they're all about.

104
00:05:18,400 --> 00:05:19,180
Otherwise,

105
00:05:19,180 --> 00:05:21,390
let's dive a little deeper and look at a few

106
00:05:21,390 --> 00:05:24,320
specific parameters for Get‑Process.

107
00:05:24,320 --> 00:05:27,790
Sometimes you need to get a bit more detail about a parameter

108
00:05:27,790 --> 00:05:30,800
than from what you can see under SYNTAX.

109
00:05:30,800 --> 00:05:34,510
The help command lets you specify one or more parameters,

110
00:05:34,510 --> 00:05:36,510
and you can use wild cards.

111
00:05:36,510 --> 00:05:38,700
This is the same information that you see when you

112
00:05:38,700 --> 00:05:40,790
run help with the ‑Full parameter.

113
00:05:40,790 --> 00:05:43,220
Now uses this technique all the time when I need to

114
00:05:43,220 --> 00:05:46,310
look at a parameter and more detail.

115
00:05:46,310 --> 00:05:50,580
Now here you can see that Id is Required.

116
00:05:50,580 --> 00:05:53,070
Under Id, see Position?

117
00:05:53,070 --> 00:05:56,040
The Id parameter is defined as named.

118
00:05:56,040 --> 00:05:59,720
This means you have to type the name of the parameter,

119
00:05:59,720 --> 00:06:02,150
or at least enough of the parameter name so PowerShell can

120
00:06:02,150 --> 00:06:04,640
figure out what parameter you want to use.

121
00:06:04,640 --> 00:06:09,390
Or, if you look at the SYNTAX, you'll see that ‑Id is not in square brackets.

122
00:06:09,390 --> 00:06:11,740
That's another way that you'll know.

123
00:06:11,740 --> 00:06:16,540
Now you can't just type Get‑Process 123 because PowerShell won't know

124
00:06:16,540 --> 00:06:20,110
that you want the Id parameter to use the value 123.

125
00:06:20,110 --> 00:06:26,610
You have to type Get‑Process space ‑Id space 123.

126
00:06:26,610 --> 00:06:29,550
Compare this to the Name parameter.

127
00:06:29,550 --> 00:06:34,640
This has a position of 0, meaning the first position.

128
00:06:34,640 --> 00:06:38,050
If you type Get‑Process space Notepad,

129
00:06:38,050 --> 00:06:43,820
PowerShell will assign Notepad as a value for the ‑Name parameter.

130
00:06:43,820 --> 00:06:48,120
Some commands like Get‑Service and Get‑Process have default behaviors.

131
00:06:48,120 --> 00:06:51,610
You don't have to specify any parameters or values.

132
00:06:51,610 --> 00:06:55,440
If the command does have a required parameter, you'll get prompted.

133
00:06:55,440 --> 00:06:58,680
If you aren't sure how to use the command, well, you know, just run it.

134
00:06:58,680 --> 00:07:01,240
Of course not in a production setting.

135
00:07:01,240 --> 00:07:02,410
In the help there,

136
00:07:02,410 --> 00:07:06,090
the pipeline input setting tells you how the command will

137
00:07:06,090 --> 00:07:08,900
process objects piped into the command.

138
00:07:08,900 --> 00:07:11,410
Now we won't get into this in great detail in this course,

139
00:07:11,410 --> 00:07:14,940
although I will give you a taste of this in the demo.

140
00:07:14,940 --> 00:07:19,510
And the last thing I want to point out is the Accept wildcard setting.

141
00:07:19,510 --> 00:07:22,980
This should indicate if you can use the *wildcard with

142
00:07:22,980 --> 00:07:28,340
the value Id doesn't use wild cards, but ‑Name does.

143
00:07:28,340 --> 00:07:32,910
One thing to be aware of is that the value may not always be accurate.

144
00:07:32,910 --> 00:07:36,490
A lot of the help content is auto generated and then polished up by a

145
00:07:36,490 --> 00:07:40,170
human writer, but mistakes can happen; however,

146
00:07:40,170 --> 00:07:42,140
don't spend a lot of time worrying about all of this.

147
00:07:42,140 --> 00:07:45,060
It never hurts to try a parameter using a wildcard.

148
00:07:45,060 --> 00:07:48,330
If it doesn't work, you'll just get a message saying that it won't work.

149
00:07:48,330 --> 00:07:51,840
You can verify then by looking at the help to see, oh, yep, I'm

150
00:07:51,840 --> 00:07:53,740
right, that doesn't use a wildcard, or oh,

151
00:07:53,740 --> 00:07:55,050
it does use a wildcard.

152
00:07:55,050 --> 00:07:59,340
So you can see here in the help if it will or not, but sometimes

153
00:07:59,340 --> 00:08:01,580
you just have to try it just to know for sure.

154
00:08:01,580 --> 00:08:05,140
The more you look at help, the easier all of this will be.

155
00:08:05,140 --> 00:08:09,550
And when I say look at help, I mean diving down to this level of detail.

156
00:08:09,550 --> 00:08:17,000
Don't just glance at the SYNTAX and expect it to make sense because it probably won't until you have much more experience with PowerShell.

