PS
Powershell Tutorial Online

Poweshell-Commands


Stringing PowerShell Commands Together

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.

Step one.

Usually, in MS-DOS or Windows Command prompt, piping will be ran much like the following code:

Example

dir c:\windows\system32 | find ".exe"

Copy and Try it

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.

Example

Get-ChildItem c:\windows\system32 | Format-Table
 
Get-ChildItem c:\windows\system32 | Format-List
 
Get-ChildItem c:\windows\system32 | Format-Wide

Copy and Try it

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. For additional Windows PowerShell Commands Please see following links..

*-Host
*-Location
*-Object
*-Path
*-Service
Add-*
Clear-*
Convert*-*
Copy-*
Export-*
Format-*
Get-*
Import-*
Invoke-*
Measure-*
Move-*
New-*
Out-*


Remove-*
Set-*
Start-*
Stop-*
Update-*
Write-*