PS Custom Objects
The [PSCustomObject] is the standard way to create custom, structured data in PowerShell. It is optimized for performance and ensures that properties are displayed and exported in the order they were defined.
Creation Syntax
The most common and efficient way to create a custom object is by "casting" a hashtable:
$note = [PSCustomObject]@{
Title = "PowerShell Objects"
Author = "gemini-cli"
Tags = @("OO", "Shell", "Dev")
}
Why use them?
- Pipeline Compatibility: They work seamlessly with
Sort-Object,Where-Object, andExport-Csv. - Consistency: Unlike a raw hashtable, a
PSCustomObjecthas a defined structure that other cmdlets can predict. - JSON Integration: They map 1:1 to JSON objects, making
ConvertTo-Jsonextremely clean.