liveBook · Manning

Object type

As explained in Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools

An object type is the runtime type classification that identifies the structure and behavior of an object.

An object type identifies the kind of object PowerShell is displaying. Formatting views use the object type name to select how that object appears, connecting runtime data to a practical presentation format. section 24.2.1

In a format definition, the object type connects several pieces:

  • A view can be named after an object type, although the name itself is not what selects the view. section 24.2.1
  • A TypeName element identifies the object type whose output should use the view. section 24.2.1
  • The view then lists properties such as error text, line, column, and error number for display. section 24.2.1

Selecting a view by type

A view targeting System.CodeDom.Compiler.CompilerError displays ErrorText, Line, Column, ErrorNumber, and LineSource as a formatted list. The object type determines which view applies; the listed properties determine what the user sees. section 24.2.1

<View>
<Name>System.CodeDom.Compiler.CompilerError</Name>           #1
<ViewSelectedBy>                                             #2
<TypeName>System.CodeDom.Compiler.CompilerError</TypeName>
</ViewSelectedBy>
<ListControl>                                                #3
<ListEntries>
<ListEntry>
<ListItems>                                                  #4
<ListItem>
<PropertyName>ErrorText</PropertyName>
</ListItem>
<ListItem>
<PropertyName>Line</PropertyName>
</ListItem>
<ListItem>
<PropertyName>Column</PropertyName>
</ListItem>
<ListItem>
<PropertyName>ErrorNumber</PropertyName>
</ListItem>
<ListItem>
<PropertyName>LineSource</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>

Inspect the XML definition to see the TypeName selector and the properties chosen for an object-type view. section 24.2.1

How Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools covers it

How deep it goes
Explains XML view structure and TypeName selection, but stops short of comprehensive formatting coverage.
Examples
Uses a System.CodeDom.Compiler.CompilerError view displaying error text, location, number, and source.
What it assumes
Assumes basic PowerShell files and XML editing, while explaining paired tags and nested structure from the start.
What you can do after
Operate/configure custom PowerShell output by associating object types with XML-defined formatting views.
How it connects
Connects object types with PowerShell formatting views, XML, and Format- commands.

Also explained in

Compare how 2 books explain object type →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools. The section links point to the parts of the book it draws on.