liveBook · Manning

Default display property set

As explained in Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

A default display property set is a declared collection of object properties selected for default presentation.

A default display property set chooses which properties PowerShell shows when it formats an object. For custom type behavior, declare it in a types.ps1xml file. section 11.2

To customize a type’s default output:

  • Declare the type and its DefaultDisplayPropertySet under PSStandardMembers. section 11.2
  • List the properties to display, such as Scheme, Host, Port, AbsoluteUri, and IsFile. section 11.2
  • Load the file with Update-TypeData, then run the object-producing command again. section 11.2

Formatting a URI

After loading the type data, [Uri]"https://github.com" displays only Scheme, Host, Port, AbsoluteUri, and IsFile instead of the full property list. section 11.2

<?xml version="1.0" encoding="utf-8" ?>
<Types>
  <Type>
    <Name>System.Uri</Name>
    <Members>
      <MemberSet>
        <Name>PSStandardMembers</Name>
        <Members>
          <PropertySet>
            <Name>DefaultDisplayPropertySet</Name>
            <ReferencedProperties>
              <Name>Scheme</Name>
              <Name>Host</Name>
              <Name>Port</Name>
              <Name>AbsoluteUri</Name>
              <Name>IsFile</Name>
            </ReferencedProperties>
          </PropertySet>
        </Members>
      </MemberSet>
    </Members>
  </Type>
</Types>

Inspect the XML structure used to declare DefaultDisplayPropertySet for System.Uri. section 11.2

How Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS covers it

How deep it goes
Explains declaration and loading through types.ps1xml, but stops short of teaching custom format and types files deeply.
Examples
Uses System.Uri, a five-property XML declaration, and the https://github.com output example.
What it assumes
Assumes basic PowerShell command use and introduces types.ps1xml configuration through a guided URI example.
What you can do after
Apply via Update-TypeData to make selected properties appear in an object’s default PowerShell output.
How it connects
Connects PowerShell formatting with types.ps1xml, format.ps1xml, object properties, and Update-TypeData.

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS. The section links point to the parts of the book it draws on.