PowerShell does a fantastic job of formatting data in the console by default,
but how does that actually work?
What's going on behind the scenes between when you run a command
and when you see the output on the screen?
Why should you care?
Sometimes you want to format data in different views and
structures than what comes by default,
and you're probably curious as to how to make that happen.
Well,
strap in because we're about to explore formatting and output with PowerShell.
Hi, my name is Matt Allford,
and I'm thrilled that you're here with me on this
course Formatting Data in PowerShell.
Let's cover a couple of housekeeping things,
and then we'll get stuck into the course content.
Firstly, as I mentioned in the course overview,
I am making an assumption that you've got some
experience with PowerShell already,
nothing too advanced, but I'm expecting you're comfortable with how the
PowerShell language system works and that it's based around objects.
You should know how PowerShell's help system works,
how to run and pipe commands, what parameters are,
that kind of thing.
Dan Stanton is a desktop support engineer for a company named Globomantics.
Among the many tools and technologies Dan has been
learning and using in his role,
PowerShell has become central to being successful with managing and
maintaining the systems that he's responsible for.
Anna Fisher is Dan's manager at Globomantics,
and she's recently asked Dan to start providing some information from the
systems that he managers in an easy to read and digest format.
Nothing too fancy is needed,
and Dan knows he can find all of the information he
needs by running PowerShell cmdlets.
But he then often spends a lot of time copying and pasting information from
the console and manually manipulating the output to get it into a format he
knows Anna is looking for. Dan's sure there's a better way to make
PowerShell do the heavy lifting for him,
and the great news is that there absolutely is.
And throughout this course,
we're going to help Dan understand formatting and basic output with PowerShell.
The course is comprised of two main modules,
starting with Formatting with PowerShell,
which is the module you're in right now.
Throughout this module,
we're going to spend a few minutes discussing and
exploring PowerShell's format system,
and you'll be able to see why and how PowerShell makes decisions
and what rules it follows on how to format data when you aren't
explicitly telling it what to do.
And then there'll be times where you will want to tell PowerShell how you
want the results of a command to be formatted and displayed.
You'll get hands on with formatting data to a table, to a list, and as wide,
which is kind of sort of like a table,
but also different. We'll spend a few minutes with the formatting views,
which are a lesser‑known capability of PowerShell's format
system, but it's one that's worth knowing.
To wrap things up,
I'll show you a couple of caveats to be aware of when formatting,
which are easy to avoid when you know about them, but a lot of beginners run
into some common issues when exploring PowerShell formatting.
The next module in this course covers working with PowerShell's
Out cmdlets, which allow you to output data,
including formatted data, to the screen or to other endpoints,
like a file or even a printer.
Yeah,
an actual printer, even in 2020. I'll introduce that module a bit more in
depth when we get to the introduction clip for that module, but for now we
need to wrap our heads around formatting. Just before we get stuck into
the content, I do want to call out that I try to build learning courses
that are very hands on, and in my opinion,
this course is no exception.
Most of the clips in this course are demo clips,
where we'll be spending time at the PowerShell console.
I also firmly believe that you will get the most out of
this course if you follow along with me,
so I really encourage you to do so.
Now, you can do that clip by clip as we go, or you might prefer to
watch a series of clips and then go through the activities and lab
exercises on your own at the end, which,
of course, is perfectly fine.
There are two things that I want to bring to your
attention to help you be successful.
The first is that there are exercise files included with
this course on the Pluralsight portal.
When you download those exercise files,
I've included all of the commands that you'll see me run in this course inside
of text‑based files with a brief description of what they do.
The folders inside of the exercise files are laid out per module, so
you'll see a folder for module 2, which is this module,
and you'll see a folder for module 3, which is the next module.
I do strongly believe that you'll solidify your knowledge more quickly
if you type the commands yourself and make mistakes.
But if you prefer to copy and paste the commands, please feel free to do so.
The second thing I want to show you is my demo environment, and
we'll be spending most of the time in this course in my
environment at the PowerShell console.
Now, I want to point out that you don't have to be
set up exactly the same as I am.
You're probably aware by now, but PowerShell is a multi‑platform utility,
and all of these exercises will work just as well on
Linux or Mac as they do on Windows.
With that said,
I've got a Windows 10 desktop and I've followed the installing
PowerShell section of Jeff Hicks's Installing and Running
PowerShell course to get PowerShell 7 installed.
If I run Get‑ComputerInfo and select the WindowsProductName and the
WindowsVersion, you'll see I'm on Windows 10 Pro and version 2004.
But like I said,
you don't need to be on this build of Windows or even Windows at all.
As long as you're running version 7 of PowerShell, that's the main thing.
If I run $PSVersionTable,
you'll see here that I'm running version 7.0.3 of PowerShell. Hmm, I
think that's the housekeeping stuff out of the way. Let's get stuck into looking at the PowerShell format system.