About format-list

I’ve been recently asked, how the format-list cmdlet selects the properties to be displayed when I do ps | fl. Why do we have Id, Handles, CPU and Name? Where do these properties come from?

This question was already answered and demonstrated on the PowerShell Team’s blog a few years ago on this page.

I couldn’t remember immediately (my bad 😛 ) and I did the following to have a look at what the engine does under the hood 😀

Trace-Command { ps | fl } -PSHost -Name (Get-TraceSource|
? Name -notmatch "Consol.*").Name

default-fl-view-trace

To summarize, PowerShell starts by Plan A and looks for a list view definition in format files.
When Plan A fails, it reports:

FormatViewBinding Information: 0 : No applicable view has been found

Then it switches to Plan B and starts by exploring the Memberset “DefaultDisplayPropertySet” of the hidden MemberSet called PSStandardMembers.

MemberResolution Information: 0 : “PSStandardMembers” present in type table.
[…]
MemberResolution Information: 0 : Found PSMemberSet member: DefaultDisplayPropertySet.

There, it finds these 4 properties:

(ps | select -fi 1).PSStandardMembers.DefaultDisplayPropertySet

default-fl-view-defaultdisplay

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s