windowspowershellfailoverclusterwindows-clustering

Custom psobject truncating the results that are added using add-member


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}

Solution

  • 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...}).

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