1 hour 43 minutes
Hello, everyone. I'm instructor Gerry Roberts, and this is Power Shell scripting
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.
First of all, piping commands, there are a couple of very useful commands you can pipe that you really should know
where. Object format list, RFL format table or F T and measure object
where object. This is the first combat 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 equal stopped.
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.
Now. One thing to notice is the Dash e Q.
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
format list is the next useful command
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.
Now this particular command is gonna look for some processor information,
then displayed as a list. So 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 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.
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.
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
and P M. P M ws all that
has its own column
in 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 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.
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.
So what this actually
did was it went through
and it found the sea Windows System 32 directory.
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
items. You also see some other items like average son
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
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.
Another item that you're gonna want to know what piping is howto pipe output to a file.
In addition to actually be able pipin commands, you can actually pump your output to a file.
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.
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
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.
And what we've done is we've done our command. So get Dash C. I am instance space
dash class name space win 32 underscored by us space
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
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.
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,
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
now. Post assessment question time.
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?
Wouldyou pipe random dot t x t
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.
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.
Create Scheduled Jobs with Windows PowerShell
The Create Scheduled Jobs with Windows PowerShell Guided IT pro Challenge from Learn on Demand ...
Learn On Demand
This Azure Automation IT Pro Challenge helps learners understand how to use the Azure Portal ...
Learn On Demand