1
00:00:02,340 --> 00:00:03,490
With these introductions,

2
00:00:03,490 --> 00:00:05,880
let's get back into a PowerShell prompt so that you

3
00:00:05,880 --> 00:00:10,140
can see these commands in action.

4
00:00:10,140 --> 00:00:13,740
Let's look at these cmdlets that work with any type of object,

5
00:00:13,740 --> 00:00:17,390
including generic objects like my vegetable objects.

6
00:00:17,390 --> 00:00:20,040
So I'll go ahead and run Get‑Vegetable.

7
00:00:20,040 --> 00:00:23,840
There's the standard output which we've seen a few times by now.

8
00:00:23,840 --> 00:00:30,040
I want to group those objects on the Color property that I see listed there.

9
00:00:30,040 --> 00:00:35,340
So I'm going to do Get‑Vegetable, pipe this to the grouping cmdlet,

10
00:00:35,340 --> 00:00:40,710
Group‑Object, and specify the property that I want to group on.

11
00:00:40,710 --> 00:00:43,660
That property parameter, by the way, is positional.

12
00:00:43,660 --> 00:00:45,060
You don't have to type it.

13
00:00:45,060 --> 00:00:49,400
PowerShell assumes if I do Group‑Object Color, that Color is the property.

14
00:00:49,400 --> 00:00:52,660
But I have it in there for the sake of clarity.

15
00:00:52,660 --> 00:00:54,840
I'll hit Enter.

16
00:00:54,840 --> 00:00:57,200
I now get a different type of result, right?

17
00:00:57,200 --> 00:00:58,720
I don't see the vegetable objects.

18
00:00:58,720 --> 00:01:01,940
They are there under that Group property.

19
00:01:01,940 --> 00:01:06,350
What I see is properties of Count and Name.

20
00:01:06,350 --> 00:01:09,540
In fact, this is a completely different type of object.

21
00:01:09,540 --> 00:01:10,780
Let's go ahead and prove that.

22
00:01:10,780 --> 00:01:15,800
Let's rerun Get‑Vegetable, and let's group on the color property,

23
00:01:15,800 --> 00:01:18,140
and I'll pipe this to get‑member.

24
00:01:18,140 --> 00:01:20,790
And you can see that this is now a

25
00:01:20,790 --> 00:01:24,650
Microsoft.PowerShell.Commands.GroupInfo object.

26
00:01:24,650 --> 00:01:26,160
And you can see the properties.

27
00:01:26,160 --> 00:01:33,640
There really aren't any methods for this particular type of object.

28
00:01:33,640 --> 00:01:35,820
Now that we understand the concepts,

29
00:01:35,820 --> 00:01:38,790
let's try this with a real PowerShell command like Get‑Process.

30
00:01:38,790 --> 00:01:42,400
And just for the sake of variety, I'm going to throw in a new parameter,

31
00:01:42,400 --> 00:01:44,340
IncludeUserName.

32
00:01:44,340 --> 00:01:45,150
When run locally,

33
00:01:45,150 --> 00:01:49,540
this will show you the username that the process is running under.

34
00:01:49,540 --> 00:01:53,440
And in fact, I'm going to group on that property Username.

35
00:01:53,440 --> 00:01:53,940
Normally,

36
00:01:53,940 --> 00:01:56,920
you would run that by itself so that you could discover that property name.

37
00:01:56,920 --> 00:01:58,530
I'm kind of jumping ahead.

38
00:01:58,530 --> 00:02:02,440
I already know that property name, so let's go ahead and group on it.

39
00:02:02,440 --> 00:02:03,450
And again, there we go.

40
00:02:03,450 --> 00:02:05,900
You can see the output there.

41
00:02:05,900 --> 00:02:08,950
Eventually, you'll learn how to filter, for example,

42
00:02:08,950 --> 00:02:15,140
to get rid of, say, those processes that don't have a username involved.

43
00:02:15,140 --> 00:02:17,630
All right, let's look at another command.

44
00:02:17,630 --> 00:02:18,980
Let's look at Get‑Service.

45
00:02:18,980 --> 00:02:21,640
Remember, you can use any property.

46
00:02:21,640 --> 00:02:25,180
So let's do Get‑Service, and let's just grab the winrm service, all right?

47
00:02:25,180 --> 00:02:28,740
So there is the default output for Get‑Service.

48
00:02:28,740 --> 00:02:34,140
However, this is not all there is to a service object.

49
00:02:34,140 --> 00:02:37,850
Let's get this service object, pipe it to get‑member,

50
00:02:37,850 --> 00:02:40,740
and look at just the properties.

51
00:02:40,740 --> 00:02:41,280
So there we go.

52
00:02:41,280 --> 00:02:45,640
So there's lots of other properties that we can work with.

53
00:02:45,640 --> 00:02:48,980
Any property that you see there is fair game for any of these

54
00:02:48,980 --> 00:02:52,000
cmdlets that need a property name to do something,

55
00:02:52,000 --> 00:02:54,240
such as grouping.

56
00:02:54,240 --> 00:02:57,040
So let's do Get‑Service,

57
00:02:57,040 --> 00:03:02,840
and I'm going to take all the services and group them on the StartType property.

58
00:03:02,840 --> 00:03:04,010
I'm going to throw in,

59
00:03:04,010 --> 00:03:07,160
and you would see this when you read the help for Group‑Object,

60
00:03:07,160 --> 00:03:10,290
I'm going to throw in the NoElement parameter because all I

61
00:03:10,290 --> 00:03:12,940
want to see is just the count and name.

62
00:03:12,940 --> 00:03:14,300
No scripting involved.

63
00:03:14,300 --> 00:03:23,000
I just told PowerShell, get these things, group them on this property, and then show me the result.

