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
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