1

I have a PowerShell script to obtain query result. The problem is I can't obtain all the result in the output when I run the script. I have 3 little points that probably means the result continue. See on the image.

How can I obtain all results when I run the script ? enter image description here

Toto
  • 89,455
  • 62
  • 89
  • 125
Makina74
  • 45
  • 6

2 Answers2

1

Since we don't know what the structure of the output object of the script looks like, it's really hard to tell what option is the best way to visualize the output.

| ConvertTo-Json is one way.

But if the output is a flat structure I would go with | Format-List *

Dennis
  • 871
  • 9
  • 29
0

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
  ]
}
mklement0
  • 382,024
  • 64
  • 607
  • 775