Format right
The next important practice in PowerShell is to format right. This means that any format cmdlets included in the pipeline should be at the far right of the pipeline. While filter left is primarily about efficiency, format right concerns the kinds of objects produced. To see this, have a look at the following output:
First, you can see that the Get-Service
cmdlet outputs the ServiceController
objects. Piping those ServiceController
objects to Format-List
, though, produces a series of objects with indecipherable properties, as shown in the following screenshot:
Once a formatting cmdlet has been executed, the only objects on the pipeline are PowerShell formatting objects which are only useful by the PowerShell host. As a general rule, the only cmdlets that can follow a formatting cmdlet in the pipeline are the output cmdlets that start with Out-
. These output cmdlets are designed to interpret these formatting objects and render formatted output accordingly. Since pipelines always...