Cmdlets & The Pipeline
The unique power of PowerShell lies in its structured command set (Cmdlets) and its ability to pass rich metadata between them via the Pipeline.
1. Cmdlets (Verb-Noun)
Cmdlets are specialized commands. They almost always follow a Verb-Noun pattern, making them highly discoverable.
- Verb: The action (e.g.,
Get,Set,New,Stop). - Noun: The target (e.g.,
Service,Process,Item,Content).
| Command | Purpose |
|---|---|
Get-Process | Lists all active processes. |
Get-Service | Lists all system services. |
New-Item | Creates a new file or folder. |
Get-Command | Lists all available commands. |
2. The Discovery Cmdlets
PowerShell is "self-documenting". These three commands are essential for learning on the fly:
# 1. Find a command
Get-Command *service*
# 2. Learn how to use it
Get-Help Get-Service -Examples
# 3. Explore its properties (The most important command!)
Get-Process | Get-Member3. The Object Pipeline
In text-based shells, a pipe (|) sends text. In PowerShell, it sends the entire object.
# Pass process objects to a filter, then to a selector
Get-Process | Where-Object { $_.CPU -gt 10 } | Select-Object Name, CPUCommon Pipeline Cmdlets
Where-Object: Filters objects based on a condition.Select-Object: Picks specific properties from an object.Sort-Object: Sorts the incoming objects.ForEach-Object: Performs an action on each item.
[!IMPORTANT] The
$_Variable In a script block (like insideWhere-Object),$_represents the current item in the pipeline. Think of it as "the object being processed right now".