Some Powershell commands (or cmdlets) – Part 4


You can use the pipeline ” | ” to filter information.

 The Curly brackets”{ }”  opens a script block

$_ represents the item as it comes across the pipeline

 “.” is used to find a process that comes across in the pipeline; ex: .cpu .pm .handles, etc


  Some Examples

“notepad”,”calc” | ForEach-Object { Start-Process $_ }

Where $_ represents the item as it comes across the pipeline

So, for the variable $_  the 1st item that comes across is called “notepad”, the 2nd item is called “calc”, and so on, so forth

So, this script will start 2 processes: notepad and calc


Get-Process notepad, calc

Note: that there are no quotations  because the Get-Process expects a string


 will tell me information about the member that I have or The object that comes across the pipeline

 Get-Process notepad | Wait-Process ;dir 

This will issue a command AFTER the process stops

So the CLI command “dir” will be executed only after I stop the process called “notepad”

 Get-Process | sort cpu -Descending | more

Lists all processes in CPU descending order

 Get-Process | where { $_.cpu -GT 1000 }

Get-Process | where { $ -GT 200MB }

Filter processes using too much CPU or Memory

 Using Sorting

Get-Process | where { $_.cpu -GT 1000 } | sort – cpu -Descending

Get-Process | where { $ -GT 200MB } | sort – pm -Descending

If you don’t use  “-Descending”,   the list comes in reverse order


Getting the first items on the list

Get-Process | where { $ -GT 20MB } | sort pm -Descending | select -First 4


Leave a Reply

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

You are commenting using your 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

%d bloggers like this: