#PSTip How to improve the display of enumerated items

When working with objects in the console you may have seen a display that resembles the following:

PS> Get-Process s* | Select-Object Name,Threads -First 5

Name           Threads
----           -------
SearchIndexer  {5092, 2732, 1100, 2040...}
services       {656, 700, 764, 6100...}
shstat         {4440, 4672, 4196, 4232...}
SkyDrive       {2696, 4352, 4604, 448...}
smss           {268, 428}

Notice that the Threads column is showing 4 thread values and then it adds an ellipsis (…) to indicate that there are more items that are not shown.
PowerShell do this regardless of console window size.

PowerShell determines how many items to include in the the display using the $FormatEnumerationLimit preference variable.
As you already seen, it’s default value is 4, but we can change it and display more values.

PS> $FormatEnumerationLimit = 7
PS> Get-Process s* | Select-Object Name,Threads -First 5

Name           Threads
----           -------
SearchIndexer  {5092, 2732, 1100, 2040, 400, 3036, 3120...}
services       {656, 700, 764, 5168, 1612, 5104, 6560}
shstat         {4440, 4672, 4196, 4232, 3548, 2384, 1872...}
SkyDrive       {2696, 4352, 4604, 448, 1816, 2332, 1688...}
smss           {268, 428}

Want to reveal all values regardless of their count? Set $FormatEnumerationLimit to -1 (undocumented).

Note: The value does not affect the underlying objects, just the display.

About the author: Shay Levy

Shay Levy is a Co-founder and editor of the PowerShell Magazine. He is a multiple-year recipient of the Microsoft MVP award, and a Microsoft Certified Trainer (MCT). Shay often covers PowerShell related topics on his blog and you can also follow him on Twitter at @ShayLevy

Related Posts

%d bloggers like this: