Skip to content

Lesson 1 of 13 · 14m

The Pipeline Moves Objects

PowerShell's pipeline binds .NET objects to parameters by value and property name — text parsing never happens unless you force it.

When you run Get-Process | Stop-Process, PowerShell never produces a line of text. Get-Process materializes System.Diagnostics.Process objects — live .NET objects, with properties like Id and WorkingSet64 and methods like Kill() — and pushes them into the pipeline. Stop-Process declares a parameter -InputObject of type Process[] that accepts pipeline input ByValue. The binder matches the object type to the parameter type and the process dies. No string was ever involved.

The bash model is wrong

You came up on ps aux | grep node | awk '{print $2}' | xargs kill. That pipeline moves text, and text parsing is where shell scripts go to die. Column positions are a contract with a program's output format, not with the data. tasklist truncates image names at 25 characters, so Microsoft.Teams.Update.exe becomes Microsoft.Teams.Update.e and your findstr match silently misses. ipconfig prints localized labels — parse IPv4 Address on a French build and you get nothing, because it prints Adresse IPv4. wmic was deprecated and then removed from Windows 11 builds entirely; thousands of for /f loops broke on an OS upgrade, not a code change.

PowerShell was designed to kill this class of bug. Jeffrey Snover's 2002 Monad Manifesto argued a shell should pass structured data, not formatted text, and twenty years later that decision is still the whole reason to use it. Get-NetIPAddress -AddressFamily IPv4 | Select-Object -ExpandProperty IPAddress works on every locale Microsoft ships, because it returns IPAddress objects and hands you the property.

How binding actually works

The pipeline binder tries ByValue first: does the incoming object's type match a parameter marked Accept pipeline input: true (ByValue)? Get-Help Stop-Process -Parameter InputObject shows exactly that. If no ByValue match exists, it tries ByPropertyName — it looks for a property on the object whose name matches a parameter. That's why 'spooler' | Get-Service works: the string binds ByValue to -Name. And it's why a CSV with a Name column pipes straight into Get-Service — each row's Name property binds ByPropertyName. Rename the column to Service and ByPropertyName finds no Name property to bind, so every row errors out. Run Get-Help Get-Service -Parameter * and read the Accept pipeline input column — it is the API contract of every cmdlet.

The contract has teeth in both directions: Import-Csv hosts.csv | Invoke-Command { hostname } never leaves the local machine. Invoke-Command -ComputerName accepts no pipeline input at all, so each row binds -InputObject ByValue and the scriptblock runs once per row, locally. Fanning out means passing the names as an argument: Invoke-Command -ComputerName (Import-Csv hosts.csv).ComputerName -ScriptBlock { hostname }. (Get-Service -ComputerName did exist in Windows PowerShell 5.1 — ByPropertyName only, never ByValue — and PowerShell 7 removed it: remoting there is Invoke-Command over WinRM or SSH, not per-cmdlet DCOM parameters.) The pipeline is typed; treat column names like parameter names.

There is a second wrong move in the same family: casting back to text because a cmdlet "doesn't take objects." [datetime] casts, [int] casts, parameter coercion handles most of it — and when it truly can't, Select-Object -ExpandProperty extracts the scalar the next stage needs without ever touching a regex. Get-WinEvent -FilterHashtable @{LogName='System';Id=7036} | Select-Object -ExpandProperty Message gives you strings because you asked for strings — deliberately, at the boundary.

Text at the edge only

Objects stay objects until you force them out. Select-Object -ExpandProperty Name unrolls one property into bare values. ConvertTo-Csv, ConvertTo-Json, and Export-* serialize on purpose. Out-String is the honest way to flatten an object to text when you truly need text — for an email body, a log line, a Write-Verbose message.

What you must not do is route objects through a formatter and keep piping. Get-Process | Format-Table | Export-Csv procs.csv does not produce a CSV of processes. Format-Table consumes the Process objects and emits Microsoft.PowerShell.Commands.Internal.Format.* wrapper objects — formatting instructions for the console host. Your CSV gets columns named ClassId2e4f51ef21dd47e99d3c952918aff9cd and formatErrorBuffer. Everyone does this once.

The practice

Keep objects alive to the last possible inch of the pipeline. Filter with Where-Object, shape with Select-Object, sort with Sort-Object, and only then emit text or a file. The idiom for a daily report is not text manipulation — it is a chain of typed stages:

Get-Process |
    Where-Object WorkingSet64 -gt 500MB |
    Sort-Object CPU -Descending |
    Select-Object -First 10 Name, Id, @{n='WorkingMB'; e={[math]::Round($_.WorkingSet64/1MB)}} |
    Export-Csv -NoTypeInformation bigprocs.csv

That runs identically on English, French, and Japanese Windows because nothing ever touched a column position. That is the entire argument for objects over text.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.