Takeaways:
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
Get-member
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 { $_.pm -GT 200MB }
Filter processes using too much CPU or Memory
Using Sorting
Get-Process | where { $_.cpu -GT 1000 } | sort – cpu -Descending
Get-Process | where { $_.pm -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 { $_.pm -GT 20MB } | sort pm -Descending | select -First 4
