With these introductions,
let's get back into a PowerShell prompt so that you
can see these commands in action.
Let's look at these cmdlets that work with any type of object,
including generic objects like my vegetable objects.
So I'll go ahead and run Get‑Vegetable.
There's the standard output which we've seen a few times by now.
I want to group those objects on the Color property that I see listed there.
So I'm going to do Get‑Vegetable, pipe this to the grouping cmdlet,
Group‑Object, and specify the property that I want to group on.
That property parameter, by the way, is positional.
You don't have to type it.
PowerShell assumes if I do Group‑Object Color, that Color is the property.
But I have it in there for the sake of clarity.
I'll hit Enter.
I now get a different type of result, right?
I don't see the vegetable objects.
They are there under that Group property.
What I see is properties of Count and Name.
In fact, this is a completely different type of object.
Let's go ahead and prove that.
Let's rerun Get‑Vegetable, and let's group on the color property,
and I'll pipe this to get‑member.
And you can see that this is now a
Microsoft.PowerShell.Commands.GroupInfo object.
And you can see the properties.
There really aren't any methods for this particular type of object.
Now that we understand the concepts,
let's try this with a real PowerShell command like Get‑Process.
And just for the sake of variety, I'm going to throw in a new parameter,
IncludeUserName.
When run locally,
this will show you the username that the process is running under.
And in fact, I'm going to group on that property Username.
Normally,
you would run that by itself so that you could discover that property name.
I'm kind of jumping ahead.
I already know that property name, so let's go ahead and group on it.
And again, there we go.
You can see the output there.
Eventually, you'll learn how to filter, for example,
to get rid of, say, those processes that don't have a username involved.
All right, let's look at another command.
Let's look at Get‑Service.
Remember, you can use any property.
So let's do Get‑Service, and let's just grab the winrm service, all right?
So there is the default output for Get‑Service.
However, this is not all there is to a service object.
Let's get this service object, pipe it to get‑member,
and look at just the properties.
So there we go.
So there's lots of other properties that we can work with.
Any property that you see there is fair game for any of these
cmdlets that need a property name to do something,
such as grouping.
So let's do Get‑Service,
and I'm going to take all the services and group them on the StartType property.
I'm going to throw in,
and you would see this when you read the help for Group‑Object,
I'm going to throw in the NoElement parameter because all I
want to see is just the count and name.
No scripting involved.
I just told PowerShell, get these things, group them on this property, and then show me the result.