When compared to formatting tables and lists, this last
format style that I want to bring to your attention being
format‑wide, it's definitely used less,
but it can be useful in specific scenarios,
so I want you to be across it.
Let's take a look. If we bring up our trusty help again with help Format‑Wide,
you'll see that format‑wide formats objects as a wide table that
displays only one property of each object being formatted.
It's got some similar parameters that format table and format list have.
And if I run Get‑Alias ‑Definition format‑wide, it has an alias of fw.
Okay, let's just run this and see what it does.
We'll go with Get‑Process and pipe that to format‑wide. As promised by the
help, we've got just a single property of each object,
which in this case,
is the process name and it's formatted that on the screen in
this kind of wide table view. Before we play around with any of
the other parameters for format‑wide,
how do you think it decided which property to show us, by
default, for the process object type.
If you're thinking that is defined in the format
definitions, you are absolutely correct.
Let's take a quick look at the format data for the process object type and we
can do that by opening the XML file that we exported a couple of clips ago
containing the format instructions for a process object.
So I'll run notepad C:\Docs and then process.xml, and let
me make that full screen, and scroll down to the very last
view that's defined here.
We can see that it's a wide view and check out this line here.
The WideItem that's defined is the ProcessName property so
it's not just luck that you're being shown the ProcessName
as the default property.
Let's jump back to the console and check out a few of the other parameters.
So Get‑Process, pipe that to Format‑Wide,
let's check out AutoSize first. So the AutoSize will fit the results on the
display as best it can and that looks pretty good to me.
There is a parameter named column that can be used to hard define
how many columns format‑wide will output to.
So let's try 3 and that looks okay. Let's try 5. Now it mostly looks okay,
but note down here to the right that one of these
values is now starting to get cut off.
That's why autosize determined that four columns was best for this output.
Now you could do something like 20, which is not really going to be very useful,
right?
So just be careful what you wish for.
All of these results have been displaying the process name, but
we can override which property is being shown by format wide by
using the property parameter.
Let's ask for the ID.
Cool. It looks okay, but there's a lot of wasted screen there.
Let's set that to four columns.
Yeah, that looks a little bit better.
Lastly, format‑wide does have the ability to group objects as
well similar to the other formatting commands. So if we roll with
Get‑Service this time and remember, we need to sort it before grouping,
so I'll pipe that across to sort object,
and I want to sort on the property named Status so results get
grouped based on whether the service is stopped or running.
From there, we can pipe that down to format‑wide and we can
group by the Status property.
If I scroll up a little bit here, you can see that all of these
services down here that are grouped are running.
And if I scroll all the way up to the top, all of these ones group together at the top are stopped.