DevOps
PowerShell
Cmdlets & Pipeline

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).
CommandPurpose
Get-ProcessLists all active processes.
Get-ServiceLists all system services.
New-ItemCreates a new file or folder.
Get-CommandLists 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-Member

3. 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, CPU

Common 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 inside Where-Object), $_ represents the current item in the pipeline. Think of it as "the object being processed right now".