PowerShell Pipelining Example

Alright pipelining in PowerShell proved to be helpful tonight. Here a quick example to get you combining multiple cmdlets.

First of lets look at a single cmdlet. Type this into your PowerShell terminal.

get-process *

That cmdlet uses a wild card that will list off all process on your local machine. Now lets add another cmdlet into the mix.

get-process * | stop-process

This isn’t a very hard syntax to decode, if you hadn’t notice yet, the pipe command is the “|” character.

Essential what we would be doing is using a stop-process command on each process. Not vary smart thing to do but you can also do something like a foreach loop and target specific processes to either stop or start them with a single line of code.

The built in help has some good infomation on pipelines, type this into your shell.

get-help about_pipeline

Additional help can be found from the PowerShell Team,
http://blogs.msdn.com/powershell/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s