1
00:00:01,140 --> 00:00:05,940
Next, let's take a look at selecting objects and parts of objects.

2
00:00:05,940 --> 00:00:10,190
Once again, Get‑Vegetable, just to reinforce the concepts,

3
00:00:10,190 --> 00:00:12,110
and pipe to Select‑Object.

4
00:00:12,110 --> 00:00:13,060
And you know what?

5
00:00:13,060 --> 00:00:15,510
I just want to see the first three vegetable objects.

6
00:00:15,510 --> 00:00:19,040
I just need a little sample. There we go.

7
00:00:19,040 --> 00:00:24,940
Select‑Object, in this situation, writes the vegetable object onto the pipeline,

8
00:00:24,940 --> 00:00:29,140
but only shows me the first three.

9
00:00:29,140 --> 00:00:32,050
We can also use Select‑Object to select properties.

10
00:00:32,050 --> 00:00:37,850
So I'm going to pipe Get‑Vegetable to a Select‑Object and specify the Count,

11
00:00:37,850 --> 00:00:42,840
Name, and State properties that I see listed there.

12
00:00:42,840 --> 00:00:45,040
Except I don't see a state.

13
00:00:45,040 --> 00:00:45,700
What happened?

14
00:00:45,700 --> 00:00:46,040
Well,

15
00:00:46,040 --> 00:00:48,140
this is something very similar to what we had just

16
00:00:48,140 --> 00:00:51,540
looked at in the last example here.

17
00:00:51,540 --> 00:00:54,550
And here's a good way to demonstrate how you can use

18
00:00:54,550 --> 00:00:58,380
Select‑Object to discover property names,

19
00:00:58,380 --> 00:00:59,740
as well as using Get‑Member.

20
00:00:59,740 --> 00:01:03,340
Sometimes Select‑Object is a little bit easier, and I'll show you why.

21
00:01:03,340 --> 00:01:06,040
So I'm going to select just the first one,

22
00:01:06,040 --> 00:01:08,120
and I'm going to combine parameters because you can

23
00:01:08,120 --> 00:01:09,280
do that here with Select‑Object.

24
00:01:09,280 --> 00:01:10,620
I'm going to tell PowerShell,

25
00:01:10,620 --> 00:01:15,060
get me the first vegetable object and select all properties,

26
00:01:15,060 --> 00:01:18,740
and you can use the wildcard there.

27
00:01:18,740 --> 00:01:19,440
There we go.

28
00:01:19,440 --> 00:01:22,950
So this is kind of like Get‑Member. I see all the property names,

29
00:01:22,950 --> 00:01:25,840
but I also see the values.

30
00:01:25,840 --> 00:01:29,130
When you just do Get‑Member, and if you look at properties,

31
00:01:29,130 --> 00:01:30,370
all you see are names.

32
00:01:30,370 --> 00:01:33,880
And sometimes it's hard to tell, okay, I see that name there,

33
00:01:33,880 --> 00:01:36,440
but what does that really mean?

34
00:01:36,440 --> 00:01:40,540
Well, when you see the property name and the value,

35
00:01:40,540 --> 00:01:44,820
often it makes it much easier to line up what it is that you're looking for.

36
00:01:44,820 --> 00:01:46,220
And in this situation,

37
00:01:46,220 --> 00:01:50,060
now I can tell that I want the CookedState. That's the

38
00:01:50,060 --> 00:01:52,440
property name that I want to use.

39
00:01:52,440 --> 00:01:57,240
So let's do Get‑Vegetable, pipe it to Select‑Object again,

40
00:01:57,240 --> 00:02:01,580
this time I'm just using the positional parameter values of Count,

41
00:02:01,580 --> 00:02:06,270
Name, and CookedState, and now I get the results that I am expecting.

42
00:02:06,270 --> 00:02:09,870
That Select‑Object trick, select a representative object,

43
00:02:09,870 --> 00:02:11,180
select all properties,

44
00:02:11,180 --> 00:02:14,640
it's a great way to discover the property names and the

45
00:02:14,640 --> 00:02:19,640
values that you might want to be working with.

46
00:02:19,640 --> 00:02:22,840
All right, let's try this now with some regular commands.

47
00:02:22,840 --> 00:02:28,240
Let's do get‑service and select the Name and StartType.

48
00:02:28,240 --> 00:02:30,540
Sure enough, that works pretty nicely.

49
00:02:30,540 --> 00:02:33,780
Let's try a new command, kind of getting tired of Get‑Service.

50
00:02:33,780 --> 00:02:35,740
Let's do get‑winevent.

51
00:02:35,740 --> 00:02:41,540
And I want to list the System event log on my computer.

52
00:02:41,540 --> 00:02:45,160
Now I'm not listing the entries, I'm just listing the log itself,

53
00:02:45,160 --> 00:02:50,540
so I can see some nice information there about the event log file.

54
00:02:50,540 --> 00:02:51,960
But maybe there's more to this.

55
00:02:51,960 --> 00:02:57,170
So let's use my little trick here, and let's list the System event log,

56
00:02:57,170 --> 00:03:01,840
pipe to Select‑Object, and look at all properties.

57
00:03:01,840 --> 00:03:02,270
There we go.

58
00:03:02,270 --> 00:03:06,740
So I can look at that, and I can see what properties I might want to work with.

59
00:03:06,740 --> 00:03:07,730
Let's try this then.

60
00:03:07,730 --> 00:03:09,440
Let's do get‑winevent.

61
00:03:09,440 --> 00:03:11,440
In this case, now that I know the properties,

62
00:03:11,440 --> 00:03:16,940
I'm going to do this for all the event logs that are listed on my system.

63
00:03:16,940 --> 00:03:20,600
I'm going to select the Logname, the Recordcount,

64
00:03:20,600 --> 00:03:25,640
the MaximumSizeInBytes, and the FileSize.

65
00:03:25,640 --> 00:03:27,730
And just to make this, again, a little bit different,

66
00:03:27,730 --> 00:03:31,140
I'm going to send this to a new cmdlet called Out‑GridView.

67
00:03:31,140 --> 00:03:35,190
This will display the results, let me bring this up here,

68
00:03:35,190 --> 00:03:39,580
in a screen that is a graphical window.

69
00:03:39,580 --> 00:03:43,140
And you can click on the column headings to sort,

70
00:03:43,140 --> 00:03:45,690
you can do additional filtering. There's really no way to

71
00:03:45,690 --> 00:03:49,520
zoom in or to make this any bigger, but there you have it.

72
00:03:49,520 --> 00:04:01,000
I can take the results, select the properties that I want, in this case, what I just listed there, and then I sent it to Out‑GridView.

