Create a custom reporting object
Documentation: Microsoft Learn
The [pscustomobject] cast applied to a hashtable literal produces one object whose properties are the hashtable keys, in the order they were written.
The script
Script reader
Inspect before you run
Inspect the script below. It does not run in this browser.
Inspection only — no command has run.
Show reference output
Inspect this example’s structure
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
[pscustomobject]
@{Name=
"Web01"
;Role=
"IIS"
;Healthy=
$true
;Checked=
Get-Date
}- Stage 1[pscustomobject]
Positional values or no named parameters
How it works
The [pscustomobject] cast applied to a hashtable literal produces one object whose properties are the hashtable keys, in the order they were written. Mixed value types cause no trouble, so a boolean and a DateTime sit alongside strings with no conversion involved.
Adapting it
Emit one of these per input item inside a loop and the function returns a collection that pipes cleanly into Sort-Object or Export-Csv with nothing further required.
If the result is unexpected
A custom reporting object has inconsistent columns or blank values.
Different branches can emit different shapes, and missing source values may be silently assigned.
- Inspect input values before constructing each PSCustomObject and use consistent property names.
Validate the result
Every row has the intended columns and marks unavailable source data explicitly.
Keep the check reliable
Define a stable report schema and test empty and partial input cases.
Primary documentation
Practise the script’s building blocks
Choose two service properties
Return only Name and Status for all services.
The sandbox is visible now. Sign in with Google only when you run or check a task; commands and temporary files are discarded when you leave.
Run a command to inspect its result.