2

I have two clusters, cluster1 with 5 nodes and cluster2 with 4 nodes. With below script the cluster1 output is getting truncated. How to address this problem?

PS C:\WINDOWS\system32> $temp = @()
PS C:\WINDOWS\system32> foreach($i in @('cluster1','cluster2')){
>> $pso = New-Object -TypeName psobject
>> $cluster = Get-Cluster $i | select name
>> $cluster_nodes = Get-ClusterNode -Cluster $cluster.Name | select name
>> $pso | Add-Member -MemberType NoteProperty -Name 'Cluster' -Value $cluster.Name
>> $pso | Add-Member -MemberType NoteProperty -Name 'Cluster_nodes' -Value $cluster_nodes.name
>> $temp += $pso
>> }

Output:

PS C:\WINDOWS\system32> $temp

Cluster         Cluster_nodes
-------         -------------
cluster1        {node1, node2, node3, node4...}
cluster2        {node1, node2, node3, node4}
Siva Dasari
  • 1,059
  • 2
  • 19
  • 40
  • Does piping the output to `| Format-Table -AutoSize` fix the issue? – Owain Esau Feb 19 '20 at 00:45
  • no, tried that. – Siva Dasari Feb 19 '20 at 00:55
  • 4
    `$formatenumerationlimit` controls this. The default value is 4. You can set it to -1 for unlimited or something else that fits your collection sizes. – AdminOfThings Feb 19 '20 at 01:53
  • @AdminOfThings Sonofagun! I've been trying to figure that one out for a LONG time. I just finished writing up a long rant about how I couldn't get it to display more than 4 items and posting it as an "answer" (which I've since deleted... O.o) when I saw your comment. Thanks a million and a half! – Matthew Feb 19 '20 at 02:06

1 Answers1

1

AdminOfThings provided the crucial pointer in a comment on the question:

Preference variable $FormatEnumerationLimit controls how many elements of a collection-valued property to display in formatted output.

E.g, $FormatEnumerationLimit = 2; [pscustomobject] @{ prop = 1, 2, 3 } prints (at most) 2 elements from .prop's value and hints at the existence of more with ...; e.g., {1, 2...}).

  • The default value is 4, but you can set it to an arbitrary positive value.

  • -1 places no limit on how many values are displayed, but note that with tabular output (implicit or explicit Format-Table) the column width may still truncate the value list.

    • Pipe to Format-List to ensure that all values are shown.

Caveat: Due to a bug as of PowerShell [Core] 7.0, setting $FormatEnumerationLimit is only effective in the global scope - see this GitHub issue.

  • As a workaround in scripts, modify the global copy, $global:FormatEnumerationLimit, temporarily (restore it to the original value before exiting the script).
mklement0
  • 382,024
  • 64
  • 607
  • 775