Advice on formatting table column

Welcome Forums General PowerShell Q&A Advice on formatting table column

This topic contains 2 replies, has 2 voices, and was last updated by

3 years, 3 months ago.

  • Author
  • #42127

    Topics: 37
    Replies: 143
    Points: 0
    Rank: Member


    I'm writing a script to give a site overview of configuration manager. By doing the below script :

    $Site = 
        Get-CimInstance -Namespace 'root\SMS\site_***' -ClassName SMS_SCI_SysResUse |
           select -Property NetworkOSPath -ExpandProperty RoleName |
           Group -property NetworkOSPath -AsHashTable -AsString 
    $column1 = @{expression="name"; width=25; label="Server"; alignment="left"}
    $column2 = @{expression="Value"; width=80; label="Role Types"; alignment="right"}
    $site | Format-Table -Wrap $column1, $column2

    It works as it should apart from a small display niggle ! Below is a line of output:

    \\A_Server {SMS SQL Server, SMS Component Server, SMS Distribution Point, SMS Site

    As you can see, if the Role Types column has more than 4 roles (Like our primary server does), it stops with ..}

    I'm trying to achieve the server name on the left, and on the right all the roles being shown. Then onto the next server and so on.

    I've been playing for a while and can't seem to get the desired result. Would anyone have any ideas ? (Thanks !)

  • #42131

    Topics: 9
    Replies: 2322
    Points: 0
    Rank: Member

    Maybe try setting your $column2 to this:

    $column2 = @{expression={ $_.Value -join ', ' }; width=80; label="Role Types"; alignment="right"}

    Doing the -join instead of leaving it as an array might help.

  • #42204

    Topics: 37
    Replies: 143
    Points: 0
    Rank: Member

    Dave, you are a genius ! Thank you, worked a treat.

The topic ‘Advice on formatting table column’ is closed to new replies.