Welcome back! In this module, we'll take a look at how PowerShell works
with objects in the pipeline and why it matters to you.
Understanding this paradigm is crucial to your success in using
and eventually scripting with PowerShell.
This is something that can be difficult for PowerShell
beginners to truly grasp, but once they do,
a lot of things begin to make sense.
PowerShell is all about working with objects in a pipeline.
You're not parsing a bunch of text to get results to look the way you want them.
You're telling PowerShell, get me these things,
do something with them, and then finally, show me the results.
PowerShell is an interactive management tool that takes advantage of this
pipeline process. And it doesn't matter if you're running PowerShell
interactively, at a console prompt as we're doing in this course,
or running PowerShell in a script or function,
it's still all about objects in the pipeline.
Traditional and legacy tools tend to be text based. Even something
like VBScript that sort of gives you objects, you still often
needed to treat those results like text in order to get the
desired output. With these tools,
and you can think of command line tools like netstat or
Linux commands like ps, they give you text,
which you often have to parse to get exactly what you want.
Now, this is not necessarily a bad thing.
Linux has terrific tools for this task like grep and awk,
assuming you know how to use them.
But Windows is not text based, right?
It's based on objects, and to a great extent this means .NET.
So it makes sense that a management tool for Windows would
be based on .NET and be object centered.
Now,
because of this dependency on .NET, Windows PowerShell
remained a proprietary language.
But, once Microsoft decided to make .NET Core available on
non‑Windows platforms and made it an open source project,
PowerShell really wasn't that far behind.
And really, that's where we are today.
The version of PowerShell that runs on Windows,
Linux, and Mac is relying on .NET Core. And even on non‑Windows
platforms, the concept is still objects in the pipeline.
When you run a PowerShell command,
it's typically creating and, in some situations,
consuming objects.
This is really what the pipeline is all about.
You get a bunch of things in PowerShell and pass them to
another command and then on to another.
Where it gets tricky is that you may start with one type of object
and end up with something completely different,
depending on what the cmdlet you are piping to is designed to do.
Now this is actually a good thing because it means you can
perform some pretty complex commands from a PowerShell prompt
with no scripting and minimal effort.
At the end of your pipeline expression,
PowerShell displays whatever is left in the pipeline to your screen.
But up until that point, it's really all about objects in the pipeline.
Of course, it helps to understand what an object means in this context.
You don't have to be a developer to use PowerShell,
but you should understand a few basic concepts.
Now for our purposes,
an object is a software representation of some thing
that you want to manage or work with.
It could be a process, service, mailbox, or vegetable. Objects have
properties, which are ways to describe it. Thinking about our vegetable, it
might have a property to control or show the color.
Maybe there's a property that gives you the number of
objects or number of vegetables.
The other common part of an object is this idea of methods.
These are actions that you can do to an object or maybe that the object does.
Continuing with our vegetable object idea,
it might have methods of, say, peel or chop.
Now don't worry, most of the time you'll use cmdlets to manipulate objects,
even though under the hood these cmdlets are working with the
properties and methods of the corresponding objects.
Now you can too, and sometimes you really have no choice.
But for now, as a beginner, you should be able to use,
and you should stick with using PowerShell cmdlets.
There are other elements to an object,
but properties and methods are the primary ones that we'll be focusing on. These are referred to generically, or collectively, as an object's members.