liveBook · Manning

View

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

A predefined view is a stored set of formatting rules targeted at a particular object type.

When PowerShell converts objects into readable output, it first checks whether their object type has a predefined view: stored formatting rules targeted at that type. section 11.2

Predefined views provide:

  • Special layouts for particular types, such as Microsoft.PowerShell.KeyHandler objects. section 11.2
  • Default formatting rules loaded from installed .format.ps1xml files when PowerShell starts. section 11.2

Customize a URI view

A System.Uri object initially displays many properties. A type-data file can define a DefaultDisplayPropertySet containing Scheme, Host, Port, AbsoluteUri, and IsFile; Update-TypeData then applies that definition, producing a shorter view. 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 of a predefined display-property set 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 type-based selection and custom type data, but stops short of teaching complete predefined-view creation.
Examples
Uses KeyHandler formatting and a customized System.Uri display-property set.
What you can do after
Evaluate/understand how PowerShell selects predefined views and applies custom display properties.
How it connects
Connects object types with the formatting system, format.ps1xml files, and type data.

Also explained in

Compare how 2 books explain view →

Related concepts

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.