3.5. Object-Based Approach in PowerShell

One important feature in PowerShell is that it is object-based. PowerShell operates on .NET, COM, and WMI objects. Everything in PowerShell is object-based.

3.5.1. Object-Based Pipelines

Command shells such as CMD.exe on Windows or BASH/CSHELL in Linux/Unix makes use of pipelines. A pipeline allows the result of one command to be passed to another command. CMD.exe, in common with the usage of Linux/Unix pipelines, typically passes strings from one command to the next. This is very useful, but it imposes the burden of string parsing on the user. In the Linux environment, the need to achieve increasingly complex string manipulation led to the development of utilities such as awk, sed, and grep, as well as Perl. You have immense flexibility when using that approach but at the expense of needing to learn multiple complex tools and languages, each with overlapping functionality.

The approach taken in Windows PowerShell is different, and better, in that .NET objects, not strings, are passed between steps in the pipeline. In the case of PowerShell, each command is typically a cmdlet, although you can also use .NET classes and their methods and properties in pipeline steps. Each object passed along a pipeline has the methods and properties common to that type of object. This enables you to use object notation to retrieve or manipulate desired components or values of each object.

One advantage of the object-based approach is that the displaying ...

Get Professional Windows® PowerShell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.