Author Posts

May 18, 2017 at 10:03 am

Hi,

Please can someone help, for some reason when i run the following code to output values in a hashtable, the output is being grouped, but if i remove the 4th item in the hashtable, the output is in a list format.

I need the output for the 4 items to be in list not grouped.

Foreach($Vm in $WAPVMs){
Get-WAPackVM -Name $VM.Name |  Select-Object Name, @{Name=“CPU”;Expression={$_.CPUCount}},
                                                             @{Name=“Memory”;Expression={$_.Memory}},
                                                             @{Name=“DiskSzie”;Expression={$_.TotalSize / 1GB}},
                                                             @{Name=“OS”;Expression={$_.OperatingSystem}}
                                                            

}

OutPut with 4 items:

Name     : ServerName
CPU      : 2
Memory   : 4096
DiskSzie : 14.919921875
OS       : Windows Server 2012 R2 Standard

Output with 3 Items

Name                CPU Memory      DiskSzie
----                --- ------      --------
ServeName     2   8192 30.3701171875   14.4

What am i doing wrong?

thanks

TommyQ

May 18, 2017 at 10:29 am

Nothing at all. By default PowerShell displays objects with 4 or fewer properties as a table, 5 or more in a list. Without doing more advanced stuff, you can just pipe the output of you select-object command to Format-List to get the results you want.