question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add -FormatEnumerationLimit parameter to Format-List and Format-Table

See original GitHub issue

Summary of the new feature / enhancement

With PowerShell, you sometimes get objects which have properties that are actually an array of objects. The Threads and Modules Properties on System.Diagnostics.Process object. When Format-List/Format-Table formats these parameters, they only include up to a certain number of occurrences, by default 4. The number of enumerations shown is determined by the automatic variable $FormatEnumerationLimit. So if you want more, you just update that variable, typically in a $Profile.

Here is the current behaviour:

PS> $FormatEnumerationLimit
4
PS> Get-Process | Select-Object -Property Name, Threads -First 4

Name                    Threads
----                    -------
AggregatorHost          {5240}
ApplicationFrameHost    {16968, 2848, 18728}
AppVShNotify            {9164}
Atom.SDK.WindowsService {4064, 4908, 4912, 19144…}

PS> $FormatEnumerationLimit = 1
PS> Get-Process | Select-Object -Property Name, Threads -First 4

Name                    Threads
----                    -------
AggregatorHost          {5240}
ApplicationFrameHost    {16968…}
AppVShNotify            {9164}
Atom.SDK.WindowsService {4064…}

I propose adding a new parameter to both Format-List and Format-Table, -FormatEnumerationLimit which overrdes the value of $FormatEnumerationLimit, but just for this command. Like this:

PS> Get-Process | Select-Object -First 4 | Format-Table Name, Threads -FormatEnumerationLimit 2

Name                    Threads
----                    -------
AggregatorHost          {5240}
ApplicationFrameHost    {16968, 2848…}
AppVShNotify            {9164}
Atom.SDK.WindowsService {4064, 4908…}

Proposed technical implementation details (optional)

  • Update each cmdlet with the extra parameter
  • Change the logic for handling enumeration limit by using the parameter value if it is specified.
  • Retain the default value and default variable handling.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:22 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
rkeithhillcommented, Nov 7, 2021

Given that this proposal is limited to the Format-List|Table commands, Format in the parameter name seems redundant. You could shorten the parameter name to -EnumerationLimit.

1reaction
jhoneillcommented, Nov 12, 2021

That’s a very weak argument against the improvement.

Our only policy is to keep backward compatibility. And even this is already unbelievable It has limits. Any new switch for an existing cmdlet breaks things. Old scripts run on new PWSH (with relatively few exceptions) but I’ve used things from PS 5 and found the customer’s servers hadn’t been upgraded from 4, I’m writing today in 7.2 and testing in 5 because it’s Windows PowerShell only on these machines, so I can’t use convertFrom-Secure string or the new operators etc. etc. “Don’t use X if you want the script to work down-level” is OK advice. It’s certainly better than "You can’t have X because then you can’t run the script somewhere that you wouldn’t want to 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use $FormatEnumerationLimit - PowerShell ...
The trick is to use the $FormatEnumerationLimit variable and assign it a higher value.
Read more >
Change $FormatEnumerationLimit
When I'm working in the PowerShell Console by default when using Format-List you see the data returned cut off. This can be annoying!...
Read more >
How can I store output from Format-Table for later use
I have a script that creates several jobs and stores two simple values in the jobs. Start-Job -ScriptBlock {param ([string]$compip) tnc $compip ...
Read more >
Tag: Format-Table
Posts about Format-Table written by Kirk Munro. ... Here is what happens if you add the AutoSize parameter to the same command you...
Read more >
Formatting objects in PowerShell with Format-Custom, ...
The Format-List cmdlet formats the output of a command as a list of properties, showing each property on a new line. This cmdlet...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found