Time
1 hour 43 minutes
Difficulty
Intermediate
CEU/CPE
2

Video Transcription

00:00
Hello, everyone. I'm instructor Gerry Roberts, and this is Power Shell scripting
00:05
in this lesson, we're gonna learn about pipi commands and piping output to a file. We learned a little bit about Pipi in our help lessen. And in this lesson, we're gonna go further into it.
00:20
First of all, piping commands, there are a couple of very useful commands you can pipe that you really should know
00:26
where. Object format list, RFL format table or F T and measure object
00:35
where object. This is the first combat that will be very useful for you
00:41
allows you to specify certain conditions that must be met for the command in order to run.
00:47
For example, here we have a get service where object property status equal stopped.
00:54
What this will dio is it'll get the current service is then mental them based on their status. So this one says status equals stopped. So it's gonna look for that where it says stopped, and it's going to show all the ones that are stopped.
01:10
Now. One thing to notice is the Dash e Q.
01:14
Usually you want to do Dash e Q and seven equal sign when you're trying to say that something equals something in a power shock
01:26
format list is the next useful command
01:30
format. DASH list allows you to form at the output in a list. So, for example, here we have get W on my object 1 30 to underscore Processor, and we have former head of the list u Z F L. You can use format dash list or you can type in just f. Ell either works in power show.
01:49
Now this particular command is gonna look for some processor information,
01:53
then displayed as a list. So as you can see here in the picture,
01:57
we have different pieces of information like caption, which is usually just some basic information about the item device I. D manufacturer and so forth. And because it's in a list is a little bit easier to read that it would be in a table.
02:13
Now there are other parameters that could be used with format less 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.
02:28
Another formatting option is format table or FT format. Dash 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 on each table has a heading here. So like handles
02:46
and P M. P M ws all that
02:50
has its own column
02:52
in each row is a different piece of information.
02:57
Now. Format Table also has some additional parameters for further organization that you can use again those air beyond this video. But that is something you could look into another thing of format table just like format list. If you do f t instead of the full format dash table that will also work.
03:16
Measure object is another very useful command. This command allows you to find metadata or, ah, 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.
03:37
So what this actually
03:38
did was it went through
03:42
and it found the sea Windows System 32 directory.
03:47
And 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 a count of how many items and this particular folder on this particular computer it looks like there's 4490
04:04
items. You also see some other items like average son
04:10
maximum minimum property. So fight that that using. And yet there are additional parameters, just like with format, table of format list that you can use to find more information. One of the very useful ones is dash word
04:25
dash. Word gets word account, so 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.
04:39
Another item that you're gonna want to know what piping is howto pipe output to a file.
04:45
In addition to actually be able pipin commands, you can actually pump your output to a file.
04:50
This is very useful for commands to get information such as the sea. I am instance item this one trust 1 30 to buy us, which is by us information.
05:02
Um, what you can do is you can run the commands a script and create files so you have all sorts of pieces of information about what you need to get
05:14
to pipe output to a file used the greater than symbol twice a the end of your command and specify the file to pipe it to, For example, here we have our 32 by us, and we want to actually put that to a text document. So we have it for later.
05:32
And what we've done is we've done our command. So get Dash C. I am instance space
05:39
dash class name space win 32 underscored by us space
05:46
and then our pipe this space f l. So we're actually gonna format it as a list before we put it in the document. And then we did our two
05:55
greater than symbols bios dot text That's the name of the file we're sending it to. There you can actually put an entire file path.
06:04
Defile does not have to be created. It will create one for you if you have not created it yet. And once that command runs,
06:13
it's gonna pipe that buy us information into a text file called by us, and you can see there in the screen shot that it pipe the output into a file for you
06:25
now. Post assessment question time.
06:28
If you wanted to pipe output to a file called random dot T x t, which is a text file, Which command would you use?
06:35
Wouldyou pipe random dot t x t
06:40
Would you greater than random dot t x t Would you do to greater than two, then random dot t x t or would you do a less than random thought? T x t Now you may pause for a moment if you want, and we'll get the answer in a second.
07:00
The answer is C. You'd use the double greater than reign of dot taxi. Remember, you have to use the double greater than when piping output to a file.

Up Next

Intro to Powershell Scripting

In this course, you will learn the fundamentals of Microsoft Powershell, which is a popular task automation and configuration management framework. In this course you will learn the basics of the tool, to get started scripting today!

Instructed By

Instructor Profile Image
Gerrianne Roberts
Professor, Network Engineering Technology
Instructor