Next, let's take a look at selecting objects and parts of objects.
Once again, Get‑Vegetable, just to reinforce the concepts,
and pipe to Select‑Object.
And you know what?
I just want to see the first three vegetable objects.
I just need a little sample. There we go.
Select‑Object, in this situation, writes the vegetable object onto the pipeline,
but only shows me the first three.
We can also use Select‑Object to select properties.
So I'm going to pipe Get‑Vegetable to a Select‑Object and specify the Count,
Name, and State properties that I see listed there.
Except I don't see a state.
What happened?
Well,
this is something very similar to what we had just
looked at in the last example here.
And here's a good way to demonstrate how you can use
Select‑Object to discover property names,
as well as using Get‑Member.
Sometimes Select‑Object is a little bit easier, and I'll show you why.
So I'm going to select just the first one,
and I'm going to combine parameters because you can
do that here with Select‑Object.
I'm going to tell PowerShell,
get me the first vegetable object and select all properties,
and you can use the wildcard there.
There we go.
So this is kind of like Get‑Member. I see all the property names,
but I also see the values.
When you just do Get‑Member, and if you look at properties,
all you see are names.
And sometimes it's hard to tell, okay, I see that name there,
but what does that really mean?
Well, when you see the property name and the value,
often it makes it much easier to line up what it is that you're looking for.
And in this situation,
now I can tell that I want the CookedState. That's the
property name that I want to use.
So let's do Get‑Vegetable, pipe it to Select‑Object again,
this time I'm just using the positional parameter values of Count,
Name, and CookedState, and now I get the results that I am expecting.
That Select‑Object trick, select a representative object,
select all properties,
it's a great way to discover the property names and the
values that you might want to be working with.
All right, let's try this now with some regular commands.
Let's do get‑service and select the Name and StartType.
Sure enough, that works pretty nicely.
Let's try a new command, kind of getting tired of Get‑Service.
Let's do get‑winevent.
And I want to list the System event log on my computer.
Now I'm not listing the entries, I'm just listing the log itself,
so I can see some nice information there about the event log file.
But maybe there's more to this.
So let's use my little trick here, and let's list the System event log,
pipe to Select‑Object, and look at all properties.
There we go.
So I can look at that, and I can see what properties I might want to work with.
Let's try this then.
Let's do get‑winevent.
In this case, now that I know the properties,
I'm going to do this for all the event logs that are listed on my system.
I'm going to select the Logname, the Recordcount,
the MaximumSizeInBytes, and the FileSize.
And just to make this, again, a little bit different,
I'm going to send this to a new cmdlet called Out‑GridView.
This will display the results, let me bring this up here,
in a screen that is a graphical window.
And you can click on the column headings to sort,
you can do additional filtering. There's really no way to
zoom in or to make this any bigger, but there you have it.
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.