Hashtable driving me mad.

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Roy Atkins Roy Atkins 2 months, 1 week ago.

  • Author
    Posts
  • #70978
    Profile photo of TommyQuality
    TommyQuality
    Participant

    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

  • #70979
    Profile photo of Roy Atkins
    Roy Atkins
    Participant

    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.

You must be logged in to reply to this topic.