{"id":3091,"date":"2010-02-18T09:16:52","date_gmt":"2010-02-18T09:16:52","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2010\/02\/18\/psstandardmembers-the-stealth-property\/"},"modified":"2019-02-18T13:05:59","modified_gmt":"2019-02-18T20:05:59","slug":"psstandardmembers-the-stealth-property","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/psstandardmembers-the-stealth-property\/","title":{"rendered":"PSStandardMembers \u2013 The Stealth Property"},"content":{"rendered":"<p>Today I got the question<\/p>\n<blockquote>\n<p><em>I\u2019ve looked into all of my.format.ps1xml files but I can\u2019t find out where Format-List is getting its default view for, say, System.Diagnostics.Process:<\/em><\/p>\n<p><font size=\"2\" face=\"Courier New\">PS&gt; <strong>ps |select -first 1 |fl<\/strong> <\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\">Id&#160;&#160;&#160;&#160;&#160; : 7616        <br \/>Handles : 543         <br \/>CPU&#160;&#160;&#160;&#160; : 10.6860685         <br \/>Name&#160;&#160;&#160; : CmdletDesigner<\/font><\/p>\n<p><em>How does it know it should display just these four properties?        <br \/>It seems there isn\u2019t any ListControl view selected by this type within those formatting files&#8230;<\/em><\/p>\n<\/blockquote>\n<p>Excellent question!&#160; Let\u2019s pick behind the curtain and see how it works.&#160; When an object gets to one of our formatting commands, we use its type to look and see if there is a VIEW defined for it.&#160; These views are defined in our formatting files in $PSHOME directory.&#160; They have filenames like xxx.Format.ps1xml .&#160; If we find it, we use it.&#160; If we don\u2019t find it, we look to see whether this type has a DefaultDisplayPropertySet defined.&#160; If it does, we use it.&#160; If it doesn\u2019t we emit all the properties either as a table or a list depending upon how many properties there are.<\/p>\n<p>&#160;<\/p>\n<p>But wait a minute \u2013 let\u2019s go back and look at this DefaultDisplayPropertySet \u2013 what\u2019s that all about?&#160; If you\u2019ve been using PowerShell a while, you\u2019ll realize that PowerShell uses a type mashup system.&#160; Mashups are really just an identity space and a mechanism for 3rd parties to add addition information into an identity space.&#160; For map mashups, the identity space is latitude\/longitude and a mechanism for someone to provide the lat\/long for all the Starbucks in the world.&#160; For PowerShell, we use TYPEs as an identity space and then have various mechanisms for 3rd parties to add extra information.&#160; One of those mechanisms is TYPE files (e.g. $pshome\/types.ps1xml ).&#160; If you take a look at the file, you\u2019ll see that we have a set of entries which are keyed off of a typename and can add extra information.&#160; If you search for System.Diagnostics.Process \u2013 you\u2019ll see a bunch of stuff.&#160;&#160; One of the things you can add to a type is a MemberSet<\/p>\n<p>&#160;<\/p>\n<p>One of the things you\u2019ll see is a super double secret MemberSet called PSStandardMembers.&#160;&#160; This is a hidden memberset that PowerShell uses for it\u2019s own purposes.&#160; In that memberset, you (we) can define something called DefaultDisplayPropertertySet which provides a set of properties that should be displayed if there isn\u2019t a view defined.&#160; Let me show you that it is really there (you can follow along at home):<\/p>\n<p><font size=\"2\" face=\"Courier New\">PS&gt; <strong>$x = Get-Process |Select -First 1        <br \/><\/strong>PS&gt; <strong>$x |Format-List<\/strong><\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\">Id&#160;&#160;&#160;&#160;&#160; : 7616      <br \/>Handles : 543       <br \/>CPU&#160;&#160;&#160;&#160; : 10.7172687       <br \/>Name&#160;&#160;&#160; : CmdletDesigner <\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\"><\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\">PS&gt; # Let me prove to you that it is hidden      <br \/>PS&gt; <strong>$x |Get-Member PSStandardMembers<\/strong>       <br \/><\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\">     <br \/><\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\">PS&gt; # It&#8217;s really there, just hidden.&#160; You can show hidden things using -Force      <br \/>PS&gt; <strong>$x |Get-Member PSStandardMembers -Force <\/strong><\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\">&#160;&#160; TypeName: System.Diagnostics.Process <\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\">Name&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; MemberType Definition      <br \/>&#8212;-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-       <br \/>PSStandardMembers MemberSet&#160; PSStandardMembers {DefaultDisplayPropertySet}<\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\"><\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\"><\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\">PS&gt; <strong>$x.PSStandardMembers<\/strong>       <br \/>PSStandardMembers {DefaultDisplayPropertySet}       <br \/><\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\">     <br \/>PS&gt; <strong>$x.PSStandardMembers.DefaultDisplayPropertySet<\/strong> <\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\">ReferencedPropertyNames : {Id, Handles, CPU, Name}      <br \/>MemberType&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; : PropertySet       <br \/>Value&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; : DefaultDisplayPropertySet {Id, Handles, CPU, Name}       <br \/>TypeNameOfValue&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; : System.Management.Automation.PSPropertySet       <br \/>Name&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; : DefaultDisplayPropertySet       <br \/>IsInstance&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; : False <\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\"><\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\"><\/font><\/p>\n<p>PS&gt; <strong>$x.PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames      <br \/><\/strong>Id     <br \/>Handles     <br \/>CPU     <br \/>Name     <br \/>PS&gt;<\/p>\n<\/p>\n<p>&#160;<\/p>\n<p>Now it really isn\u2019t secret we just haven\u2019t talked about it much.&#160; It is documented @ MSDN <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd878267(VS.85).aspx\">HERE<\/a> .<\/p>\n<p>PSStandardMembers is used for a number of things in addition to DefaultDisplayProperties.&#160; In particular, it is used to control object serialization.&#160; You can find out more about that in my blog entry <a href=\"http:\/\/blogs.msdn.com\/powershell\/archive\/2007\/05\/01\/object-serialization-directives.aspx\">HERE<\/a>.<\/p>\n<p>&#160;<\/p>\n<p>Enjoy! <\/p>\n<p>Jeffrey Snover [MSFT]    <br \/>Distinguished Engineer     <br \/>Visit the Windows PowerShell Team blog at:&#160;&#160;&#160; <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a>     <br \/>Visit the Windows PowerShell ScriptCenter at:&#160; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I got the question I\u2019ve looked into all of my.format.ps1xml files but I can\u2019t find out where Format-List is getting its default view for, say, System.Diagnostics.Process: PS&gt; ps |select -first 1 |fl Id&#160;&#160;&#160;&#160;&#160; : 7616 Handles : 543 CPU&#160;&#160;&#160;&#160; : 10.6860685 Name&#160;&#160;&#160; : CmdletDesigner How does it know it should display just these four [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3091","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>Today I got the question I\u2019ve looked into all of my.format.ps1xml files but I can\u2019t find out where Format-List is getting its default view for, say, System.Diagnostics.Process: PS&gt; ps |select -first 1 |fl Id&#160;&#160;&#160;&#160;&#160; : 7616 Handles : 543 CPU&#160;&#160;&#160;&#160; : 10.6860685 Name&#160;&#160;&#160; : CmdletDesigner How does it know it should display just these four [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/3091","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=3091"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/3091\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=3091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=3091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=3091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}