You're using Format-Custom
to visualize a data structure (as with all Format-*
cmdlets, Format-Custom
's purpose is to create a representation for the human observer, not for programmatic processing).
Format-Custom
respects the - rarely used - $FormatEnumerationLimit
preference variable , which defaults to 4
and specifies the maximum number of elements of an array-valued property to display, with additional, omitted elements represented as ...
Therefore, the immediate solution to your problem is to set $FormatEnumerationLimit
to a large enough value, to ensure that all array elements render:
# Use a large enough value to ensure that *all* elements are shown.
$FormatEnumerationLimit = [int]::MaxValue
# A simplified example of outputting an object with an array-valued property
[pscustomobject] @{ foo = 1..5 } | Format-Custom
Note: It's worth saving the old $FormatEnumerationLimit
value and restoring it afterwards; normally, you could achieve this effect more conveniently by placing both commands inside & { ... }
, so as to create a local, transient copy of the variable, but due to a bug - still present as of PowerShell 7.2 - that doesn't work in this particular case - see GitHub issue #888.
The above yields the following, showing that all 5
elements - more than the default limit of 4
- are shown:
class PSCustomObject
{
foo =
[
1
2
3
4
5
]
}
Alternatively, you can use ConvertTo-Json
for quick visualization, which - as a data-processing cmdlet - isn't subject to the $FormatEnumerationLimit
limit:
[pscustomobject] @{ foo = 1..5 } | ConvertTo-Json # add -Depth as needed.
Pitfall: ConvertTo-Json
limits its recursion depth to 2
, which means that more deeply nested data structures won't be shown in full - use the -Depth
parameter as needed to prevent truncation - see this post for more information.
The above yields:
{
"foo": [
1,
2,
3,
4,
5
]
}