Commands, Cmdlets, and the Pipeline¶
PowerShell is built around the idea that commands should be predictable, structured, and capable of working together through an object‑based pipeline. Understanding cmdlets, the pipeline, and the tools used to inspect commands is essential for effective scripting.
Cmdlets¶
A cmdlet is a compiled .NET class that performs a specific operation. It does not read or manipulate plain text. Instead, it receives and outputs objects. Each cmdlet follows a strict Verb‑Noun naming convention, such as Get-Process or Set-Service, and exposes a defined set of parameters that PowerShell binds automatically.
When a cmdlet runs, PowerShell loads the underlying .NET class, executes its methods, and returns structured objects. This design ensures consistent behavior, strong typing, and reliable automation across the entire environment.
The Object‑Based Pipeline¶
The pipeline connects commands by passing objects, not strings. When a cmdlet produces output, it emits .NET objects that retain their properties and methods. The next command in the pipeline receives these objects directly, without needing to parse text.
For example:
Get-Process | Sort-Object CPU
Get-Process outputs process objects. Sort-Object receives those objects and sorts them by the CPU property. No text parsing occurs at any stage.
This model allows commands to interact with precision. Each stage of the pipeline works with structured data, enabling filtering, sorting, grouping, and transformation without relying on fragile string manipulation.
Chaining Commands and Inspecting Output¶
PowerShell provides tools to discover commands, inspect their structure, and understand the objects they produce.
Discovering Commands: Get-Command¶
Get-Command lists available cmdlets, functions, scripts, and aliases. It is used to explore the command surface of PowerShell and locate the appropriate tool for a task.
Reading Documentation: Get-Help¶
Get-Help displays detailed information about a command, including syntax, parameters, examples, and descriptions. It is the primary source for understanding how a cmdlet behaves.
Inspecting Objects: Get-Member¶
Get-Member reveals the properties and methods of the objects produced by a command. It is essential for understanding what data is available and how it can be manipulated.
Selecting Data: Select-Object¶
Select-Object extracts specific properties from objects or creates calculated properties. It is used to shape output for further processing or display.
Sorting Data: Sort-Object¶
Sort-Object orders objects based on one or more properties. It works directly with object values, not text fields.
Filtering Data: Where-Object¶
Where-Object filters objects based on conditions applied to their properties. It evaluates each object and passes only those that meet the specified criteria.
Practice Commands¶
Try to run these commands in a PowerShell terminal and see what their output is:
Get-Command
Get-Help Get-Process
Get-Process | Get-Member
Get-Process | Select-Object Name, CPU
Get-Process | Sort-Object CPU
Get-Process | Where-Object { $_.CPU -gt 1 }