PowerShell for Windows Admins

May 18 2017   2:24PM GMT

Table or List

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


A question on the forum asked why a object is displayed in a table if it has 4 or fewer properties and as  a list if it  has more than 4 properties:

PS> [PSCustomObject]@{P1=1; P2=2; P3=3; P4=4}

P1 P2 P3 P4
-- -- -- --
 1  2  3  4

PS> [PSCustomObject]@{P1=1; P2=2; P3=3; P4=4; P5=5}

P1 : 1
P2 : 2
P3 : 3
P4 : 4
P5 : 5

This is a built in mechanism in PowerShell and is done automatically.

The quick way to get the output in table format is to use Format-Table

PS> [PSCustomObject]@{P1=1; P2=2; P3=3; P4=4; P5=5} | Format-Table

P1 P2 P3 P4 P5
-- -- -- -- --
 1  2  3  4  5

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: