1
00:00:01,040 --> 00:00:04,020
There's a component of the formatting system that doesn't

2
00:00:04,020 --> 00:00:08,280
really get talked about much, well, at least not in my experience.

3
00:00:08,280 --> 00:00:11,840
I want you to be across it because you might find it useful.

4
00:00:11,840 --> 00:00:14,840
Let's check out formatting views.

5
00:00:14,840 --> 00:00:20,140
Each of the format cmdlets in PowerShell have a parameter named view.

6
00:00:20,140 --> 00:00:23,480
This can be used to define different formatting views other than the

7
00:00:23,480 --> 00:00:28,620
default one if there are any views defined in the formatting files. If

8
00:00:28,620 --> 00:00:31,390
there are no alternate views defined, well,

9
00:00:31,390 --> 00:00:33,840
this parameter isn't going to do much for you.

10
00:00:33,840 --> 00:00:36,690
Let's take a quick look at the format data again with

11
00:00:36,690 --> 00:00:39,280
Get‑FormatData. For the TypeName,

12
00:00:39,280 --> 00:00:42,710
I'll paste the value for System.Diagnostics.Process that's

13
00:00:42,710 --> 00:00:45,140
still on my clipboard from a previous clip,

14
00:00:45,140 --> 00:00:49,380
and I'll drop in the PowerShell version as 5.1. Check out this

15
00:00:49,380 --> 00:00:52,230
property here named FormatViewDefinition,

16
00:00:52,230 --> 00:00:55,340
and you can see there are four entries in total here.

17
00:00:55,340 --> 00:00:59,940
We've got process. Priority, StartTime, and process again.

18
00:00:59,940 --> 00:01:04,330
This means there are different views for the process object type that we could

19
00:01:04,330 --> 00:01:07,940
leverage when formatting the process data in PowerShell.

20
00:01:07,940 --> 00:01:11,040
I'm going to press the up arrow to get that command back, and then put a

21
00:01:11,040 --> 00:01:14,870
closing bracket, followed by pressing the home key to go to the start of

22
00:01:14,870 --> 00:01:19,180
the command, and I'm going to put an opening bracket there. And I'll press

23
00:01:19,180 --> 00:01:23,040
end on my keyboard again to get back to the end of the command, and then

24
00:01:23,040 --> 00:01:25,570
put .FormatViewDefinition.

25
00:01:25,570 --> 00:01:28,940
So we can look a bit deeper at that specific property.

26
00:01:28,940 --> 00:01:29,870
By doing this,

27
00:01:29,870 --> 00:01:33,540
we get a bit more information on those four views that are defined.

28
00:01:33,540 --> 00:01:38,160
We can now see that process, Priority, and StartTime are all table‑based

29
00:01:38,160 --> 00:01:42,740
views and that the second process view is a wide‑based view.

30
00:01:42,740 --> 00:01:47,400
I've still got this information stored in the XML file from the previous clip.

31
00:01:47,400 --> 00:01:52,940
So again, let's run notepad and specify the path to the process.xml file.

32
00:01:52,940 --> 00:01:56,850
And I'll expand that to use the screen real estate here. And

33
00:01:56,850 --> 00:01:59,140
in there, if you look towards the top,

34
00:01:59,140 --> 00:02:03,620
we start by defining a Configuration and ViewDefinitions,

35
00:02:03,620 --> 00:02:05,680
and then a new view is defined.

36
00:02:05,680 --> 00:02:08,940
This one is the default view named process.

37
00:02:08,940 --> 00:02:10,760
If I scroll down a little,

38
00:02:10,760 --> 00:02:14,190
that first view gets closed, and look at this, another view

39
00:02:14,190 --> 00:02:17,640
gets defined, and this one is called Priority.

40
00:02:17,640 --> 00:02:22,120
This view is for the same type of data, and it's also based on a table.

41
00:02:22,120 --> 00:02:24,710
But notice here that it's actually doing some grouping

42
00:02:24,710 --> 00:02:27,740
based on the PriorityClass property.

43
00:02:27,740 --> 00:02:30,300
And lastly, if we scroll down a little bit more,

44
00:02:30,300 --> 00:02:33,570
there's a third view defined here named StartTime.

45
00:02:33,570 --> 00:02:36,350
And this one is doing some grouping based on the date,

46
00:02:36,350 --> 00:02:41,340
and it's also using a ScriptBlock to calculate that property.

47
00:02:41,340 --> 00:02:44,470
Let's jump back into the PowerShell console, and I'll show these

48
00:02:44,470 --> 00:02:49,730
to you. If I run Get‑Process and pipe that down to Format‑Table

49
00:02:49,730 --> 00:02:53,080
and then specify the view parameter, one of those alternate

50
00:02:53,080 --> 00:02:57,440
views was called StartTime, so let's give that a go.

51
00:02:57,440 --> 00:03:00,510
What you see here in the output, if I scroll up,

52
00:03:00,510 --> 00:03:03,470
is a custom view that is grouping the results based

53
00:03:03,470 --> 00:03:05,420
on the start time of the process.

54
00:03:05,420 --> 00:03:08,300
So instead of us having to do the grouping manually,

55
00:03:08,300 --> 00:03:11,440
this PowerShell view will do it for us.

56
00:03:11,440 --> 00:03:15,800
One interesting thing to note here is that there are some duplicate tables,

57
00:03:15,800 --> 00:03:17,880
and that's because this data is getting grouped,

58
00:03:17,880 --> 00:03:20,730
but it hasn't been sorted first. So really,

59
00:03:20,730 --> 00:03:24,570
we should do a Get‑Process, pass that to sort based on the

60
00:03:24,570 --> 00:03:28,560
StartTime, and then send it down to Format‑Table and specify

61
00:03:28,560 --> 00:03:31,240
the alternate view of StartTime.

62
00:03:31,240 --> 00:03:33,940
And now that looks a little bit better.

63
00:03:33,940 --> 00:03:37,100
If you don't want to dig around in the format data to figure out

64
00:03:37,100 --> 00:03:40,160
what views are available for each object type,

65
00:03:40,160 --> 00:03:43,410
there's a handy little trick that I remember from a few years ago,

66
00:03:43,410 --> 00:03:46,140
and I can't remember where I saw it, but if you run a

67
00:03:46,140 --> 00:03:48,560
command and pipe it to format command,

68
00:03:48,560 --> 00:03:53,140
you can do specify the view parameter and then just put in an incorrect name,

69
00:03:53,140 --> 00:03:56,040
so I'll just put a as the view name.

70
00:03:56,040 --> 00:04:00,210
The PowerShell error message here tells us that the view can't be found,

71
00:04:00,210 --> 00:04:02,940
but it then actually goes and tells us what views are

72
00:04:02,940 --> 00:04:04,840
available for this object type.

73
00:04:04,840 --> 00:04:06,780
So that's a quick tip if you want to find the

74
00:04:06,780 --> 00:04:12,000
formatting views for an object type, but you don't want to dig around in the format data.

