liveBook · Manning

Custom object

As explained in Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

PSCustomObject is a PowerShell wrapper object type that exposes a selected set of properties.

A custom object is a PowerShell object containing only the properties you choose. Select-Object creates one when trimming a richer object, preserving property boxes while changing the object type. section 8.8 section 10.8

Select process properties

Run Get-Process | Sort-Object CPU -Descending | Select-Object Name,ID,CPU. The pipeline now contains custom objects rather than process objects, so PowerShell formats the output using its general PSObject rules. section 8.8

A custom object still contains properties. To retrieve a property's value instead of another object containing that property, use Select-Object -ExpandProperty. For example, expanding ResourceGroupName returns strings that another command can accept. section 10.8

How Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS covers it

How deep it goes
Explains property selection, PSObject formatting, and value extraction, but stops short of constructing custom objects manually.
Examples
Demonstrates process selection and Azure resource-group projection with Get-Process, Get-AzResourceGroup, Select-Object, and Get-Member.
What it assumes
Assumes familiarity with PowerShell commands, pipelines, objects, and properties while clarifying the difference between objects and property values.
What you can do after
Apply it via Select-Object to shape pipeline data or expand a property into a value accepted by another command.
How it connects
Connects custom objects with pipelines, properties, Select-Object, ExpandProperty, Get-Member, and strings.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS. The section links point to the parts of the book it draws on.