Chapter 8: Objects: Data by another name
The introduction emphasizes that objects are central to PowerShell and directs readers to a starting section based on their programming experience.
After this chapter you will be able to
- Objects properties methods and collections. Explain how the section's table analogy maps rows to objects, columns to properties, actions to methods, and the whole table to a collection.
- Displayed columns versus available data. Explain why Get-Process displays only some available information and what happens to that information when output is piped to another command.
- Stable access to object data. Explain how objects let PowerShell work with information by name rather than by its position in displayed text, so rearranging the output does not require rewriting commands.
- Costs of parsing text output. Trace the section’s hypothetical text-only process example and explain why filtering rows and extracting process IDs by character position creates extra, fragile work.
- Discovering object members. Explain when to use Get-Member rather than Get-Help, and describe what Get-Member lists when you pipe a cmdlet’s output to it.
- Pipeline objects before display. Explain why Get-Member can inspect properties and methods that are absent from a cmdlet’s on-screen output.
- Property values and access. Explain that properties hold values describing an object, such as its name or ID, and that a property can be read even when it cannot be changed.
- Object methods as actions. Explain that a method is an action an object can take, such as a process object's Kill method terminating the process.
- Cmdlets instead of methods. Justify the section's preference for cmdlets over executing object methods, using process termination as an example of a task that can be done either way.
- Property-based sort order. Explain how Sort-Object reorders objects by a property and how -Descending changes the default ascending order.
- Choosing properties with Select-Object. Explain how Select-Object takes pipeline objects and lets you specify the properties to display, including properties normally hidden by PowerShell’s display rules. State that -Property is positional, so its name can be omitted.
- Pipeline Objects and Final Formatting. Explain that objects remain in the pipeline until the last command runs, when PowerShell uses the remaining objects and its formatting rules to produce output. Trace how Get-Process supplies process objects and Sort-Object changes their order without changing their type.
- Selected Properties and Object Types. Explain why Select-Object creates a custom PSObject containing the requested properties rather than removing properties from a process object. Describe why selecting Name, ID, and CPU changes the default display.
- Get-Member Pipeline Type Tracing. Describe how piping output to gm reveals the type of object at that point in a command line. Explain that gm itself outputs MemberDefinition objects, so piping its output to another gm examines those new objects.
- Finding object properties. Explain why PowerShell help is not the place to look for an object's properties and how to use Get-Member to see them.
- Pipeline output and object types. Explain why adding gm to a pipeline may show nothing, and why the object type at each pipeline step matters.
What it builds on
- Connecting one command to another: Less work for you (chapter 6) · Connecting commands through the pipeline.
- Asking for help (chapter 3) · Using Get-Help to learn about commands.
- Using cmdlets that modify the system: Killing processes (chapter 6) · Uses cmdlets to terminate processes.
Section by section
Introduction
The introduction emphasizes that objects are central to PowerShell and directs readers to a starting section based on their programming experience.
8.1 What are objects?
This section introduces PowerShell objects through an in-memory table analogy and explains why command output shows fewer properties than are available.
- Objects properties methods and collections: Explain how the section's table analogy maps rows to objects, columns to properties, actions to methods, and the whole table to a collection.
Why it matters: These terms give you a way to describe what PowerShell commands produce and what you can do with the results. - Displayed columns versus available data: Explain why Get-Process displays only some available information and what happens to that information when output is piped to another command.
Why it matters: A short display does not mean the other information has been lost to later commands.
Key terms: object, property, method, collection, Get-Process, properties, pipeline, ConvertTo-Html
8.2 Understanding why PowerShell uses objects
The section explains why PowerShell represents command output as objects rather than plain text, emphasizing less fragile data handling and a historical fit with Windows.
- Stable access to object data: Explain how objects let PowerShell work with information by name rather than by its position in displayed text, so rearranging the output does not require rewriting commands.
Why it matters: This is why you can focus on the information you need instead of maintaining commands tied to a display layout. - Costs of parsing text output: Trace the section’s hypothetical text-only process example and explain why filtering rows and extracting process IDs by character position creates extra, fragile work.
Why it matters: The example shows the text-manipulation overhead that PowerShell’s objects are meant to avoid. - Historical fit of objects: Explain why representing data as objects was a natural choice given PowerShell’s Windows-only origins, and state that the same mindset can be applied beyond Windows.
Why it matters: It explains why objects suited PowerShell’s origins without treating them as a Windows-only idea.
Key terms: objects, column name, in-memory table, Get-Process, grep, parsing text, ProcessName, object-oriented, Windows
8.3 Discovering objects: Get-Member
This section shows how to inspect the members and type of PowerShell objects, including information not shown in default output.
- Discovering object members: Explain when to use Get-Member rather than Get-Help, and describe what Get-Member lists when you pipe a cmdlet’s output to it.
Why it matters: Get-Member helps you discover what you can work with beyond the information initially displayed. - Pipeline objects before display: Explain why Get-Member can inspect properties and methods that are absent from a cmdlet’s on-screen output.
Why it matters: The columns you see on screen are not all the information available to the next command in a pipeline. - Object type name: Describe where Get-Member shows an object’s type name and what that name identifies.
Why it matters: Noticing TypeName helps you identify the kind of object you are inspecting.
Key terms: Get-Member, gm, members, properties, methods, pipeline, collection of objects, TypeName, type of object
8.4 Using object attributes, or properties
This section explains what object properties contain and why PowerShell shows some properties that are absent from .NET documentation.
- Property values and access: Explain that properties hold values describing an object, such as its name or ID, and that a property can be read even when it cannot be changed.
Why it matters: Reading properties is a basic way to get useful information from PowerShell objects. - PowerShell added property types: Describe why Get-Member can show several kinds of properties and why some do not appear in .NET documentation.
Why it matters: It explains why a property you can use in PowerShell might be missing from the object's .NET documentation.
Key terms: property, value, read-only, Get-Member, extensible type system, ETS, AliasProperty, ScriptProperty, NoteProperty
8.5 Using object actions, or methods
The section introduces object methods as actions but recommends using cmdlets for the tasks covered in this book.
- Object methods as actions: Explain that a method is an action an object can take, such as a process object's Kill method terminating the process.
Why it matters: This helps you recognize what a method represents when you encounter one on an object. - Cmdlets instead of methods: Justify the section's preference for cmdlets over executing object methods, using process termination as an example of a task that can be done either way.
Why it matters: For the tasks taught here, cmdlets let you focus on getting the job done without needing .NET programming background.
Key terms: methods, Kill method, process object, cmdlets, .NET programming
8.6 Sorting objects
This section shows how to reorder PowerShell objects by one or more properties with Sort-Object.
- Property-based sort order: Explain how Sort-Object reorders objects by a property and how -Descending changes the default ascending order.
Why it matters: It lets you put the objects you care about most at the top of a list. - Multiple sort properties: Describe how supplying multiple property values to -Property sorts objects when their first sort values are equal.
Why it matters: A second sort property gives tied objects a useful order.
Key terms: Sort-Object, -Property, -Descending, ascending order, comma-separated list, process ID
8.7 Selecting the properties you want
This section shows how Select-Object chooses which properties to show, can keep the first or last objects, and differs from criteria-based filtering.
- Choosing properties with Select-Object: Explain how Select-Object takes pipeline objects and lets you specify the properties to display, including properties normally hidden by PowerShell’s display rules. State that -Property is positional, so its name can be omitted.
Why it matters: Choosing properties helps you control what appears on screen or in output such as an HTML table. - Object subsets versus criteria filtering: Distinguish Select-Object’s -First and -Last parameters from criteria-based filtering with Where-Object.
Why it matters: This distinction helps you choose between taking a fixed number of results and keeping results that match a condition.
Key terms: Select-Object, -Property, properties, positional, -First, -Last, Where-Object
8.8 Objects until the end
This section shows how object types can change along a PowerShell pipeline and how the objects left at the end determine the output display.
- Pipeline Objects and Final Formatting: Explain that objects remain in the pipeline until the last command runs, when PowerShell uses the remaining objects and its formatting rules to produce output. Trace how Get-Process supplies process objects and Sort-Object changes their order without changing their type.
Why it matters: Following the objects through each command helps explain why the final output looks as it does. - Selected Properties and Object Types: Explain why Select-Object creates a custom PSObject containing the requested properties rather than removing properties from a process object. Describe why selecting Name, ID, and CPU changes the default display.
Why it matters: Selecting properties changes the objects in the pipeline, which can also change how the result appears. - Get-Member Pipeline Type Tracing: Describe how piping output to gm reveals the type of object at that point in a command line. Explain that gm itself outputs MemberDefinition objects, so piping its output to another gm examines those new objects.
Why it matters: Checking or talking through the object type after each command helps resolve pipeline confusion.
Key terms: pipeline, objects, Sort-Object, Out-File, Select-Object, PSObject, properties, process object, gm, Get-Member
8.9 Common points of confusion
This section highlights common mistakes when inspecting objects and reading PowerShell pipelines.
- Finding object properties: Explain why PowerShell help is not the place to look for an object's properties and how to use Get-Member to see them.
Why it matters: Looking at the objects themselves helps you find properties that command help does not list. - Pipeline output and object types: Explain why adding gm to a pipeline may show nothing, and why the object type at each pipeline step matters.
Why it matters: Tracking what each step outputs helps you predict whether the next command has anything useful to work with. - Readable pipeline spacing: State the section's typing convention for pipeline characters.
Why it matters: Consistent spacing makes pipelines easier to read.
Key terms: help files, properties, gm, Get-Member, pipeline, objects, Stop-Process, pipeline character
8.10 Lab
8.11 Lab answers
Where this is used later
- How PowerShell passes data down the pipeline (chapter 10) · Understanding pipeline data builds on the distinction between the displayed view and the data passed along.
- Working with the default formatting (chapter 11) · Working with default formatting builds on knowing that the visible columns are a selection.
- Plan B: Pipeline input ByPropertyName (chapter 10) · Pipeline input by property name builds on the significance of named data.
- Plan A: Pipeline input ByValue (chapter 10) · Using Get-Member to inspect command output.
- Formatting tables (chapter 11) · Recognizing object properties as the values available for display
- The CIM way: Invoking methods (chapter 15) · Introduces invoking methods as a way to work with objects.
- Cross-platform remoting (chapter 13) · Introduces actions that can be performed with objects.
- ForEach-Object confusion (chapter 15) · Introduces methods as actions on objects.
Concepts explained in this chapter
- Get-MemberGet-Member is a PowerShell cmdlet that displays the members, including properties and methods, of input objects.
- methodA method is a callable operation associated with an object that can direct the object to perform an action.
- Select-ObjectSelect-Object is a PowerShell cmdlet that selects specified properties or creates customized objects from input objects.
- Sort-ObjectSort-Object is a PowerShell cmdlet that orders input objects according to specified property values.
- custom objectPSCustomObject is a PowerShell wrapper object type that exposes a selected set of properties.
- PowerShellPowerShell 3 is the third major version of the PowerShell command-line shell.
- parsingText parsing is the process of analyzing textual content to identify, extract, or transform structured information.
- collectionA collection is a container that groups multiple values as a single data object.
- Export-CSVExport-CSV is a PowerShell cmdlet that converts objects to comma-separated values and writes them to a file.
- Out-FileOut-File is a PowerShell cmdlet that writes command output to a file.
- type nameA typename is the unique name identifying an object's type.
- aliasA parameter alias is an alternate name accepted by a command for one of its parameters.
- object typeAn object type is the runtime classification that determines an object's available structure and behavior.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
