1
00:00:01,040 --> 00:00:03,530
The final Out cmdlet we're going to explore is a

2
00:00:03,530 --> 00:00:06,040
pretty cool one named Out‑GridView.

3
00:00:06,040 --> 00:00:09,640
Let's dive back into the console one last time.

4
00:00:09,640 --> 00:00:13,340
Hopefully, by now you've guessed what we're going to take a look at first.

5
00:00:13,340 --> 00:00:15,240
Yep, the help file.

6
00:00:15,240 --> 00:00:18,340
Let's check out the help for Out‑GridView.

7
00:00:18,340 --> 00:00:23,060
So, OutGridView will send the output from a command to a grid view

8
00:00:23,060 --> 00:00:26,940
in an interactive table in a separate window.

9
00:00:26,940 --> 00:00:30,210
Because this cmdlet requires actual user interface,

10
00:00:30,210 --> 00:00:34,060
it's only available in Windows systems that support the Windows desktop,

11
00:00:34,060 --> 00:00:36,930
but I've got a bonus command to show you towards the end of

12
00:00:36,930 --> 00:00:39,940
this clip as well that works cross‑platform.

13
00:00:39,940 --> 00:00:42,640
Let's check it out, because this one is pretty cool.

14
00:00:42,640 --> 00:00:45,460
We'll run Get‑Process again and pipe that across to

15
00:00:45,460 --> 00:00:48,440
Out‑GridView and give that a go.

16
00:00:48,440 --> 00:00:49,410
After a moment,

17
00:00:49,410 --> 00:00:52,810
we get this external pop‑out window displayed that has the

18
00:00:52,810 --> 00:00:55,440
output from the Get‑Process command.

19
00:00:55,440 --> 00:00:56,790
Let me make that full screen,

20
00:00:56,790 --> 00:00:58,800
and we'll have a look at a couple of the features that

21
00:00:58,800 --> 00:01:01,540
are here in this user interface.

22
00:01:01,540 --> 00:01:06,050
So firstly, I can sort any of these columns here just by clicking on them,

23
00:01:06,050 --> 00:01:11,140
so I could sort the Id and I could also sort then on the ProcessName.

24
00:01:11,140 --> 00:01:14,050
At the very top of the window, there's a filter box,

25
00:01:14,050 --> 00:01:18,240
which can be used to filter on any of the content that's in the output here.

26
00:01:18,240 --> 00:01:20,580
So in there I will type logon,

27
00:01:20,580 --> 00:01:24,940
and the window filters to the only result that contains the word logon.

28
00:01:24,940 --> 00:01:26,720
Underneath the filter window,

29
00:01:26,720 --> 00:01:30,280
there's an option to be more specific and add criteria to filter on,

30
00:01:30,280 --> 00:01:34,440
so I'll select the Id and the ProcessName properties. And for the

31
00:01:34,440 --> 00:01:40,010
ProcessName let's filter on those that contain svc, and for the Id

32
00:01:40,010 --> 00:01:43,000
we can click on this condition and we get a number of standard

33
00:01:43,000 --> 00:01:44,940
conditions to select from.

34
00:01:44,940 --> 00:01:48,240
For this one, I'll choose the is between condition,

35
00:01:48,240 --> 00:01:51,400
and let's look for any that have an Id between,

36
00:01:51,400 --> 00:01:55,040
say, 4,000 and 6,000.

37
00:01:55,040 --> 00:01:56,930
Okay, there's only one result there,

38
00:01:56,930 --> 00:02:00,860
so let me change that to between 2,000 and 6,000.

39
00:02:00,860 --> 00:02:06,040
And the results update in real time, and we've now got four results there.

40
00:02:06,040 --> 00:02:08,470
You can rearrange these columns in the view.

41
00:02:08,470 --> 00:02:12,620
So if I click on the ProcessName heading here and then drag it across,

42
00:02:12,620 --> 00:02:16,480
it lets me move the location so I could then reshuffle some of

43
00:02:16,480 --> 00:02:19,540
these columns around to get what I'm looking for.

44
00:02:19,540 --> 00:02:22,980
Now let's go back to the console and try a few other things.

45
00:02:22,980 --> 00:02:27,890
You can use select object to select just a few properties and pipe those down

46
00:02:27,890 --> 00:02:32,240
to Out‑GridView and only those properties will be displayed.

47
00:02:32,240 --> 00:02:36,620
Alternatively, you could select all properties and pipe those to Out‑GridView,

48
00:02:36,620 --> 00:02:40,040
and indeed, all of them will be displayed as well.

49
00:02:40,040 --> 00:02:42,490
It does take a little bit longer here to render because of

50
00:02:42,490 --> 00:02:45,820
the size of the data coming through, but down the bottom here,

51
00:02:45,820 --> 00:02:49,250
I've now got this horizontal scroll bar with all of these

52
00:02:49,250 --> 00:02:52,740
properties per object being displayed.

53
00:02:52,740 --> 00:02:55,850
If I rerun the command to select just the name and the

54
00:02:55,850 --> 00:02:58,540
id and send those to Out‑GridView,

55
00:02:58,540 --> 00:03:02,940
but this time I want to use a couple of different parameters of Out‑GridView.

56
00:03:02,940 --> 00:03:04,580
The first one is Title,

57
00:03:04,580 --> 00:03:07,670
which allows you to set a custom name for the title of the

58
00:03:07,670 --> 00:03:12,140
window that pops up, so I'll just call it MyData.

59
00:03:12,140 --> 00:03:15,590
The second parameter is named PassThru, which tells the

60
00:03:15,590 --> 00:03:19,280
cmdlet to send items down the pipeline from the interactive

61
00:03:19,280 --> 00:03:22,840
window as input to other commands.

62
00:03:22,840 --> 00:03:27,290
So this one here is probably another exception of where an Out cmdlet can

63
00:03:27,290 --> 00:03:30,660
actually be manipulated to send data down the pipeline,

64
00:03:30,660 --> 00:03:33,540
which it normally wouldn't do by default.

65
00:03:33,540 --> 00:03:37,620
So if I were now to pipe that to Export‑Csv and pick a

66
00:03:37,620 --> 00:03:42,840
path where I want to save that CSV, I'll show you how the PassThru works.

67
00:03:42,840 --> 00:03:48,240
There's our Out‑GridView, and notice at the top that it's got a title of MyData.

68
00:03:48,240 --> 00:03:51,630
But notice in the background that in the PowerShell console we

69
00:03:51,630 --> 00:03:54,440
haven't been given our command prompt back.

70
00:03:54,440 --> 00:03:56,760
That's because we used the PassThru parameter,

71
00:03:56,760 --> 00:03:59,330
and this command is now waiting for data to send

72
00:03:59,330 --> 00:04:02,940
down the pipeline to Export‑Csv.

73
00:04:02,940 --> 00:04:06,520
Also, down the bottom right there, there are now these OK and

74
00:04:06,520 --> 00:04:09,440
Cancel boxes which weren't there before.

75
00:04:09,440 --> 00:04:12,270
I'm going to hold down the Ctrl button and then click on a

76
00:04:12,270 --> 00:04:14,640
few different processes in the output here,

77
00:04:14,640 --> 00:04:18,390
and then I'll click on the OK button and we get returned to the PowerShell

78
00:04:18,390 --> 00:04:24,790
console and we've got the prompt back as well. Let me run import‑csv and specify

79
00:04:24,790 --> 00:04:28,540
the path of the CSV file from that previous command,

80
00:04:28,540 --> 00:04:32,040
and it's pulled in the data that I selected from the grid window.

81
00:04:32,040 --> 00:04:33,800
So when I selected that data,

82
00:04:33,800 --> 00:04:37,930
the Pass‑Thru parameter told Out‑GridView to send that data,

83
00:04:37,930 --> 00:04:40,530
and only that data, down the pipeline,

84
00:04:40,530 --> 00:04:45,560
which was down to Export‑Csv. Last thing for Out‑GridView,

85
00:04:45,560 --> 00:04:47,500
and I have mentioned this elsewhere in the course,

86
00:04:47,500 --> 00:04:51,220
but I want to cover it again now while we're here, is that this is the

87
00:04:51,220 --> 00:04:55,640
only Out cmdlet that cannot accept formatted data.

88
00:04:55,640 --> 00:05:00,080
If we grab the processes again and pipe that to Format‑List and then try

89
00:05:00,080 --> 00:05:04,040
and send formatted data to Out‑GridView, we'll get an error that the data

90
00:05:04,040 --> 00:05:07,840
format is not supported by Out‑GridView.

91
00:05:07,840 --> 00:05:11,320
Now that's everything that I've got for you for Out‑GridView. but I do

92
00:05:11,320 --> 00:05:13,980
want to show you another cool command that is similar,

93
00:05:13,980 --> 00:05:15,470
and it's cross‑platform.

94
00:05:15,470 --> 00:05:17,540
It's a bit of a bonus, really.

95
00:05:17,540 --> 00:05:18,490
To get this command,

96
00:05:18,490 --> 00:05:23,540
we need to install a PowerShell module from Microsoft named ConsoleGuiTools,

97
00:05:23,540 --> 00:05:25,960
which we can do by running Install‑Module

98
00:05:25,960 --> 00:05:31,950
Microsoft.PowerShell.ConsoleGuiTools. Depending on whether you have

99
00:05:31,950 --> 00:05:34,990
installed anything from the PowerShell Gallery before or not,

100
00:05:34,990 --> 00:05:37,140
you may or may not get this prompt.

101
00:05:37,140 --> 00:05:39,050
I do trust the PowerShell Gallery,

102
00:05:39,050 --> 00:05:43,630
so I'm going to type y there to proceed. And after a few moments,

103
00:05:43,630 --> 00:05:48,010
the module is now installed. Let's run Get‑Command ‑Module

104
00:05:48,010 --> 00:05:52,980
Microsoft.PowerShell.ConsoleGuiTools to see what commands are

105
00:05:52,980 --> 00:05:55,640
available in the module that we've just installed.

106
00:05:55,640 --> 00:05:59,940
And there's only one, which is Out‑ConsoleGridView.

107
00:05:59,940 --> 00:06:03,100
We'll give that a try by running Get‑Process and

108
00:06:03,100 --> 00:06:06,440
piping it to Out‑ConsoleGridView.

109
00:06:06,440 --> 00:06:08,640
Whoa, how cool is that?

110
00:06:08,640 --> 00:06:11,270
It's a similar grid view to what we just worked with,

111
00:06:11,270 --> 00:06:14,760
but this time it's running from inside of the console session

112
00:06:14,760 --> 00:06:17,940
rather than being an external GUI tool.

113
00:06:17,940 --> 00:06:22,010
I can press my down arrow here to move down the objects, and then

114
00:06:22,010 --> 00:06:24,840
I can press the space bar to mark the items.

115
00:06:24,840 --> 00:06:29,440
So let me mark a few of these, and you can see them getting marked with an x.

116
00:06:29,440 --> 00:06:33,750
If I press Enter to accept, it takes me back to the PowerShell console,

117
00:06:33,750 --> 00:06:38,340
and it has output the objects that I selected while I was in the grid view.

118
00:06:38,340 --> 00:06:41,030
Let's run it again to go back in there and have another look

119
00:06:41,030 --> 00:06:44,800
around. At the top here, we've got a filter box,

120
00:06:44,800 --> 00:06:50,240
so I could type something like srv, which will filter the results on the fly.

121
00:06:50,240 --> 00:06:53,870
I could also enter something like 22, which will filter the

122
00:06:53,870 --> 00:06:57,840
objects with 22 in any of the property values.

123
00:06:57,840 --> 00:07:01,360
I'm going to escape out of that and go back to the console and we'll run

124
00:07:01,360 --> 00:07:05,290
the same command again, and it's actually got a parameter named filter

125
00:07:05,290 --> 00:07:08,340
where we can pass an object to filter through.

126
00:07:08,340 --> 00:07:12,910
If I type svc here, notice the output is immediately filtered with

127
00:07:12,910 --> 00:07:18,330
that value. Similar to Out‑GridView, there's also a Title parameter,

128
00:07:18,330 --> 00:07:23,320
so I'll set that to MyGridView, and at the top left here it's

129
00:07:23,320 --> 00:07:25,740
changed the title of the output.

130
00:07:25,740 --> 00:07:26,480
Lastly,

131
00:07:26,480 --> 00:07:29,540
there is an OutputMode parameter which allows you to change it

132
00:07:29,540 --> 00:07:32,340
from the default to something like Single.

133
00:07:32,340 --> 00:07:35,660
So if I were to do that, this time if I use the arrows to scroll

134
00:07:35,660 --> 00:07:39,650
through the objects and select one by pressing space, this time it

135
00:07:39,650 --> 00:07:42,440
puts a circle there instead of an x.

136
00:07:42,440 --> 00:07:47,070
If I select another object by using the space bar, it moves the circle as

137
00:07:47,070 --> 00:07:51,040
I'm now only allowed to select a single object at a time.

138
00:07:51,040 --> 00:07:58,000
If I press Enter to accept that, it will return the output of the single result back on screen.

