1
00:00:01,040 --> 00:00:03,090
With formatting tables out of the way,

2
00:00:03,090 --> 00:00:07,050
let's spend a few minutes looking at another popular format style,

3
00:00:07,050 --> 00:00:08,840
lists.

4
00:00:08,840 --> 00:00:10,200
Okay, as usual,

5
00:00:10,200 --> 00:00:14,740
let's spend a moment checking out the help by running help Format‑List.

6
00:00:14,740 --> 00:00:18,100
So this will format the output as a list of properties in

7
00:00:18,100 --> 00:00:21,340
which each property appears on a new line.

8
00:00:21,340 --> 00:00:23,540
Seems straightforward enough, right?

9
00:00:23,540 --> 00:00:25,630
Just like writing a shopping list.

10
00:00:25,630 --> 00:00:27,470
Do people still even write those?

11
00:00:27,470 --> 00:00:29,970
Anyway, here in the syntax block,

12
00:00:29,970 --> 00:00:34,140
there's a few similar parameters between Format‑List and Format‑Table.

13
00:00:34,140 --> 00:00:36,740
And, of course, there's an alias for Format‑List.

14
00:00:36,740 --> 00:00:44,140
So if I run Get‑Alias ‑Definition format‑list, we'll see the alias is simply fl.

15
00:00:44,140 --> 00:00:46,810
All right, let's just run Get‑Process here.

16
00:00:46,810 --> 00:00:49,310
And in case you didn't watch the previous clip,

17
00:00:49,310 --> 00:00:52,440
by default, this outputs as a table.

18
00:00:52,440 --> 00:00:55,680
I'm just going to rerun that and pipe it to the more command because I

19
00:00:55,680 --> 00:00:59,040
want to take a quick look at these table headers here.

20
00:00:59,040 --> 00:01:02,140
Take special note here to some of the names as to how they are

21
00:01:02,140 --> 00:01:05,810
formatted in the table and also note that we are seeing seven

22
00:01:05,810 --> 00:01:08,840
different properties in this table view.

23
00:01:08,840 --> 00:01:11,350
Let's rerun Get‑Process, and this time,

24
00:01:11,350 --> 00:01:15,740
we'll override the default formatting by piping it to Format‑List.

25
00:01:15,740 --> 00:01:20,240
As expected, we get a list view of properties for every object.

26
00:01:20,240 --> 00:01:22,980
Each object is separated by a blank line,

27
00:01:22,980 --> 00:01:27,140
and each property of the object is displayed on a new line.

28
00:01:27,140 --> 00:01:31,100
One thing worth noting here is take a look at the names of these properties.

29
00:01:31,100 --> 00:01:35,610
So they're quite different to what we just saw when we formatted to a table.

30
00:01:35,610 --> 00:01:39,910
And also, we're only seeing five properties here in the list view.

31
00:01:39,910 --> 00:01:43,240
Whereas in the table view, we were saying seven.

32
00:01:43,240 --> 00:01:46,840
By now, you're starting to get exposed to some of the nuances with the

33
00:01:46,840 --> 00:01:50,210
formatting system and that things that are displayed to us aren't

34
00:01:50,210 --> 00:01:54,240
always the raw underlying data of the objects.

35
00:01:54,240 --> 00:01:56,370
Let's try grouping the results here.

36
00:01:56,370 --> 00:01:57,670
Similar to Format‑Table,

37
00:01:57,670 --> 00:02:02,940
we need to sort the objects first before grouping them with the format command.

38
00:02:02,940 --> 00:02:04,690
So I'll run Get‑Process.

39
00:02:04,690 --> 00:02:08,940
I'll pipe that across to Sort‑Object and sort on the Name property.

40
00:02:08,940 --> 00:02:09,840
And from there,

41
00:02:09,840 --> 00:02:12,890
we can send it to Format‑List and then use the GroupBy

42
00:02:12,890 --> 00:02:15,960
parameter to group the results by the name.

43
00:02:15,960 --> 00:02:19,190
And we can see that the formatting has taken care

44
00:02:19,190 --> 00:02:21,260
of grouping the results for us.

45
00:02:21,260 --> 00:02:23,410
So, for example, at the bottom here,

46
00:02:23,410 --> 00:02:28,170
there are two objects that match the name WmiPrvSE,

47
00:02:28,170 --> 00:02:31,640
but only one that matches the name of winlogon.

48
00:02:31,640 --> 00:02:33,270
For the next couple of examples,

49
00:02:33,270 --> 00:02:36,920
I'm going to run Get‑Process and just grab the winlogon process.

50
00:02:36,920 --> 00:02:39,810
So we don't have a lot of data being output to the screen that

51
00:02:39,810 --> 00:02:42,440
we have to keep scrolling up and down for.

52
00:02:42,440 --> 00:02:45,490
Let me pipe that to Format‑List with no parameters,

53
00:02:45,490 --> 00:02:48,350
and we get those five properties that PowerShell decides

54
00:02:48,350 --> 00:02:51,540
to show us by default for a list view.

55
00:02:51,540 --> 00:02:54,480
Now I've seen a lot of beginners think that if you

56
00:02:54,480 --> 00:02:56,410
pipe a command to Format‑List,

57
00:02:56,410 --> 00:03:00,040
that you will get shown all of the properties of that object.

58
00:03:00,040 --> 00:03:01,070
That is, in fact,

59
00:03:01,070 --> 00:03:04,430
incorrect because the formatting system could be choosing to

60
00:03:04,430 --> 00:03:07,080
display just a number of properties back to you,

61
00:03:07,080 --> 00:03:09,940
which is exactly what's happening here.

62
00:03:09,940 --> 00:03:12,300
To understand what properties are on this object,

63
00:03:12,300 --> 00:03:15,890
you could pipe it to Get‑Member, which is absolutely fine,

64
00:03:15,890 --> 00:03:18,600
and in most cases, it's recommended.

65
00:03:18,600 --> 00:03:20,860
But sometimes you might want to see the properties

66
00:03:20,860 --> 00:03:22,760
with the actual values as well.

67
00:03:22,760 --> 00:03:24,230
On occasion,

68
00:03:24,230 --> 00:03:26,620
seeing the values right in front of you can actually make it

69
00:03:26,620 --> 00:03:29,240
easier to determine what you're working with.

70
00:03:29,240 --> 00:03:32,630
So a little trick we can use is to pipe it to Format‑List,

71
00:03:32,630 --> 00:03:36,380
but then use the Property parameter and then use the wild card or

72
00:03:36,380 --> 00:03:40,340
asterisk to tell PowerShell we want to see all properties.

73
00:03:40,340 --> 00:03:43,090
In fact, because the Property parameter is positional,

74
00:03:43,090 --> 00:03:44,630
you don't even need to specify it.

75
00:03:44,630 --> 00:03:48,940
You could just have Format‑List * or fl *.

76
00:03:48,940 --> 00:03:50,220
And as you can see,

77
00:03:50,220 --> 00:03:52,470
there are many more properties than the five we were

78
00:03:52,470 --> 00:03:55,240
being shown just a moment ago.

79
00:03:55,240 --> 00:03:56,990
If I press the up arrow,

80
00:03:56,990 --> 00:04:01,240
we can choose what properties we want the Format‑List command to output for us.

81
00:04:01,240 --> 00:04:04,030
And because the Property parameter is positional,

82
00:04:04,030 --> 00:04:06,140
wow, say that three times fast,

83
00:04:06,140 --> 00:04:09,630
we can just put the property names without specifying the parameter,

84
00:04:09,630 --> 00:04:13,240
and we'll get just those two returned in the output.

85
00:04:13,240 --> 00:04:16,720
There is something you can do in PowerShell called custom properties.

86
00:04:16,720 --> 00:04:19,980
And look, I don't want to bog you down with the details too much,

87
00:04:19,980 --> 00:04:22,560
but I want to show you that you can make use of a custom

88
00:04:22,560 --> 00:04:26,070
property in the format commands to modify the output that

89
00:04:26,070 --> 00:04:28,250
you're seeing. For example,

90
00:04:28,250 --> 00:04:30,250
the property name that we're looking at here for

91
00:04:30,250 --> 00:04:33,540
the process name is simply Name.

92
00:04:33,540 --> 00:04:38,700
What if we wanted to modify that to say Process Name instead? I'll up arrow

93
00:04:38,700 --> 00:04:43,590
that to get the command back and then remove Name and replace it with an @

94
00:04:43,590 --> 00:04:49,210
symbol and two curly brackets to define a custom expression. Inside of that,

95
00:04:49,210 --> 00:04:52,910
I can type Name equals Process Name.

96
00:04:52,910 --> 00:04:57,620
And because I'm using a space, I've put Process Name in double quotes there.

97
00:04:57,620 --> 00:05:01,720
I then need to use a semicolon and then use the keyword Expression,

98
00:05:01,720 --> 00:05:05,740
which is where I need to define what the value is going to be.

99
00:05:05,740 --> 00:05:08,040
I'll put an equals sign and another set of

100
00:05:08,040 --> 00:05:10,570
brackets. And inside of those brackets,

101
00:05:10,570 --> 00:05:14,880
I'm going to use $_, which is a way of telling PowerShell that I

102
00:05:14,880 --> 00:05:18,330
want the current object coming down the pipeline. And then I'm going

103
00:05:18,330 --> 00:05:22,580
to specify .name to tell PowerShell that I want the value of this

104
00:05:22,580 --> 00:05:26,620
custom expression to be the name property of the current process

105
00:05:26,620 --> 00:05:28,940
coming down the pipeline.

106
00:05:28,940 --> 00:05:32,700
If I run that, notice the value is the same as before,

107
00:05:32,700 --> 00:05:35,330
but the name of the result is now Process Name

108
00:05:35,330 --> 00:05:38,440
instead of just Name as it was before.

109
00:05:38,440 --> 00:05:42,240
This is something you can do with any of the format commands.

110
00:05:42,240 --> 00:05:45,040
The last thing I want to show here, and again this actually

111
00:05:45,040 --> 00:05:48,640
applies to all of the format commands, is that so far I've been

112
00:05:48,640 --> 00:05:53,440
piping commands to a format command, which then outputs it to screen.

113
00:05:53,440 --> 00:05:57,080
You can use the InputObject parameter of a format command to

114
00:05:57,080 --> 00:06:00,240
specify the objects that you want to be formatted.

115
00:06:00,240 --> 00:06:04,040
So let's define a variable of $processes. And in

116
00:06:04,040 --> 00:06:06,340
that, we'll just store Get‑Process.

117
00:06:06,340 --> 00:06:12,200
Now remember that variable contains the unformatted object data of processes.

118
00:06:12,200 --> 00:06:14,340
Nothing more, nothing less.

119
00:06:14,340 --> 00:06:18,800
I could now run Format‑List and use the InputObject parameter and

120
00:06:18,800 --> 00:06:22,800
specify the $processes variable, and PowerShell will take those

121
00:06:22,800 --> 00:06:25,440
objects and format them as a list.

122
00:06:25,440 --> 00:06:26,170
Functionally,

123
00:06:26,170 --> 00:06:32,000
it's the same as piping it across to Format‑List, but I did want you to be aware of that capability.

