Piping commands can save quite a lot of time. Another way of looking at piping is stringing items or commands together. In this tutorial, you will learn how to string PowerShell commands together.
Setup
If you have not already done so, click open Windows PowerShell ISE.
Need help with cloud hosting? Try Server Intellect. We used them for our cloud hosting services and we are very happy with the results!
Step one.
Usually, in MS-DOS or Windows Command prompt, piping will be ran much like the following code:
Code Block
dir c:\windows\system32 | find “.exe”
The command performs directory listing of c:\windows\system32 and then pipes the output to the find command to filter for lines that contain the string “.exe”. When the same command is ran in PowerShell, we receive an error of course. Keep in mind that various changes have been made that commands such as the one above no longer work in PowerShell, it is implemented in another way.
Recall that DIR is an alias to Get-ChildItem, so by running the code below (one at a time), you will receive the appropriate output in the three formats provided to you per line.
Code Block
Get-ChildItem c:\windows\system32 | Format-Table
Get-ChildItem c:\windows\system32 | Format-List
Get-ChildItem c:\windows\system32 | Format-Wide
Below is a small glimpse of what each output would appear like by format listing, the listing will come out to be several pages long of course.
Table Format

List Format

Wide Format

As you see, Get-ChildItem continues to return the same exact data every time, regardless in which format it is presented in.
Step two.
Output looking too clean? Of course! Every command that is typed in the console is automatically piped to Out-Default. What is Out-Default? It is a Cmdlet that is in charge of figuring out how to render the output of a given command, if no format is specified of course.
A Few Last Words…
Every object has a view registered to it. The particular view defines which formatter to use. We discuss output more in depth in another tutorial. Join us next time for additional Windows PowerShell tutorials! Till then…
We used over 10 web hosting companies before we found Server Intellect. Our new server with cloud hosting,was set up in less than 24 hours. We were able to confirm our order over the phone. They responded to our inquiries within an hour. Server Intellect’s customer support and assistance are the best we’ve ever experienced.