>> Hello everyone. I'm instructor Gerri Roberts,
and this is PowerShell scripting.
In this lesson, we're going to learn about
piping commands and piping output to a file.
We learned a little bit about
>> piping in our help lesson.
>> In this lesson we're going to go further into it.
First of all, Piping Commands,
there are a couple of very useful commands
that you can pipe that you really should know,
Where-object, format-List or FL,
format Table or FT, and measure-object.
Where-object, this is
the first cmdlet that will be very useful for you.
Allows you to specify certain conditions that must be
met for the command in order to run.
For example, here we have a get-service,
where-object, property status equals stopped.
What this will do is it'll get the current services,
then filter them based on their status.
This one says status equals stopped,
it's going to look for that where it says
stopped and it's going to show
all the ones that are stopped.
Now, one thing to notice is the -eq.
Usually you want to do -eq and
seven-equals sign when you're trying to
say that something equals
something in a PowerShell command.
Format-List is the next useful command.
Format-Lists allows you to format the output in a list,
for example here we have get w my on object when
3200 sewer processor and
we have formatted the list using FL.
You can use Format-List or you can type in just FL,
either works in PowerShell.
Now, this particular command is going to look for
some processor information then displayed as a list.
As you can see here in the picture,
we have different pieces of information like caption,
which is usually just some basic
information about the item,
device ID, manufacturer, and so forth.
Because it's in a list,
is a little bit easier to
read than it would be in a table.
Now, there are other parameters that can be used with
Format-List to further organize the list.
However, that's beyond what
>> we're going to be doing here.
>> But that is something to be
aware of that you can look for later.
Another formatting option is Format-table or FT.
Format-table allows you to format
your output as a table, for example,
here we have get process and FT. You can see
here it is now a table
and each table has a heading here,
so like handles and PM, PM, Ws,
all that has its own column,
and each row is a different piece of information.
Now, Format-table also has
some additional parameters for
further organization that you can use.
Again, those are beyond this video,
but that is something that you could look into.
Other thing with Format-table
just like Format-List if you
do FT instead of the full Format-table,
that will also work.
Measure-object is a another very useful command.
This command allows you to find metadata or
certain pieces of information
about an object, such as a file.
For example, here we have
>> a command get child item path,
>> the path of the file, then measure object.
What this actually did was it went
through and it found the C Windows system 32 directory.
Then it got all the child items,
which are all the items
that are actually just listed in that folder.
Then provided information.
Here it's very simple.
It just gave you account of
how many items in
this particular folder on this particular computer,
it looks like there's 4,490 items.
You'll also see some other items like average son,
maximum, minimum property, stuff like that,
that using in yet there are additional parameters
just like with format table and
format list that you can use to find more information.
One of the very useful ones is -word,
-word gets word count.
That's pretty cool if you're working on a file like
a Word file or another type of document,
you can actually get word count
>> without opening the file.
>> Another item,
you're going to want to know what piping is,
how to pipe output to a file.
In addition to actually being able to pipe in commands,
you can actually pipe your output to a file.
This is very useful for commands to get information,
such as the CIM instance item.
This one shows when 32BIOS,
which is bios information.
What you can do is you can run
the commands as a script and create
files so you have all pieces of
information about what you need to get.
To pipe output to a file,
use the greater than symbol twice at
the end of your command and
specify the file to pipe it to.
For example, here,
we have our 32Bios and we want
to actually put that to
a text document so we have it for later.
What we've done is we've done our commands,
so get-CIM instance -class name
Win32_bios and then our pipe, then space FL.
We're actually going to format it as
a list before we put it in the document.
Then we did our two greater than symbols BIOS.text,
that's the name of the file we're sending it to.
There, you can actually put an entire file path.
The file does not have to be created.
It will create one for you,
if you have not created it yet.
Once that command runs,
and it's going to pipe that bios information
into a text file called bios.
You do see there in the screenshot that
it pipe the output into a file for you.
Now, post-assessment question time.
If you wanted to pipe output to
a file called random.txt,
which is a text file,
which command would you use?
Would you pipe random.txt?
Would you greater than random.txt?
Would you do two greater than random.txt?
Or would you do a less than random.txt?
Now, you may pause for a moment if you want,
and we'll get the answer in a second.
The answer is C. You would use
the double greater than random.txt.
Remember, you have to use the double greater
than when piping output to a file.