Working with Objects¶
PowerShell operates on objects, not text. Every command produces objects, and every stage of the pipeline receives and manipulates those objects. Understanding how objects work is essential for writing reliable scripts.
Properties and Methods¶
Objects expose two kinds of members:
Properties¶
Properties represent data stored in the object. They describe the object’s state.
For example, a process object has properties such as:
NameIdCPUWorkingSet
Properties are accessed directly:
(Get-Process).Name
Methods¶
Methods are actions the object can perform. They represent behavior.
For example, a process object includes methods such as:
Kill()CloseMainWindow()
Methods are invoked with parentheses:
(Get-Process notepad).Kill()
Properties describe; methods act.
Object Types¶
Every object in PowerShell has a type, which defines its structure and behavior.
Types come from the .NET runtime, and they determine:
- Which properties the object has
- Which methods it exposes
- How it behaves in the pipeline
You can inspect an object’s type with:
Get-Process | Get-Member
The TypeName field identifies the underlying .NET class, such as:
System.Diagnostics.Process
Different commands output different types, and understanding these types is the foundation of effective scripting.
How PowerShell Converts Objects Between Pipeline Stages¶
When objects move through the pipeline, PowerShell performs implicit conversions to ensure compatibility between commands. The pipeline does not pass text; it passes full .NET objects. Each command receives the object and decides how to interpret it.
PowerShell handles conversions in several ways:
1. Property Binding¶
If a command expects a specific property, PowerShell extracts that property from the incoming object.
Example:
Get-Process | Select-Object Name
Select-Object receives full process objects but extracts only the Name property.
2. Type Adaptation¶
PowerShell adapts .NET objects into a uniform structure so that commands can work with them consistently. This allows different object types to be processed with the same pipeline tools.
3. Formatting Happens Last¶
Formatting does not occur in the pipeline. It happens only after the pipeline completes.
This means:
- The pipeline always passes objects
- Only the final output is converted to text for display
If a formatting cmdlet appears in the middle of a pipeline, it breaks object flow because it converts objects into formatting instructions. This is why formatting cmdlets should only appear at the end.