Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To customize PowerShell 7 output, export an existing format definition or create a .Format.ps1xml file, edit its views, then load it with Update-FormatData. Use -PrependPath when your definition should take precedence over an existing view; use -AppendPath for an additional definition. Formatting changes how objects are displayed, not the objects or properties flowing through the pipeline.

What a PowerShell formatting file changes

A formatting file is XML that describes how PowerShell displays objects. Microsoft’s about_Format.ps1xml explains that “the formatting affects the display only.” A format view does not change an object’s properties or transform the data sent to the next pipeline command.

A file has a Configuration root and a ViewDefinitions container. Each view has a name, identifies object types or a selection set, and specifies a display control. It can also use properties or script blocks to supply displayed values.

PowerShell supports four view layouts:

  • Table: displays selected fields in columns, useful for compact comparisons.
  • List: displays fields as labeled entries, useful when objects have more detail than fits in a table.
  • Wide: displays a single selected value across columns, favoring density over detail.
  • Custom: uses a more specific control and layout.

PowerShell 6 and later define default views in source code as well as through formatting data. The Windows PowerShell 5.1 format-file collection is therefore not the complete source of PowerShell 7’s defaults. You can still add views for new types or define a replacement view for an existing type.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
PowerShell for Sysadmins: Workflow Automation Made Easy
  • Book - powershell for sysadmins: workflow automation made easy
  • Language: english
  • Binding: paperback

Create a custom view from an existing definition

For a first customization, inspect and export a relevant existing definition. This example uses System.IO.FileInfo, the type commonly returned for file objects.

  1. Inspect the current formatting data:
    Get-FormatData -TypeName System.IO.FileInfo
  2. Export a starting file: create the destination directory if needed, then run:
    Get-FormatData -TypeName System.IO.FileInfo | Export-FormatData -LiteralPath $HOME/Format/FileInfo.Format.ps1xml
  3. Edit the XML: open $HOME/Format/FileInfo.Format.ps1xml in a text editor. Keep the view or views you need, and edit their displayed fields or layout. Make sure the view control suits how you intend to display the data.
  4. Load the edited file: for a replacement view, run:
    Update-FormatData -PrependPath $HOME/Format/FileInfo.Format.ps1xml
  5. Test the output: run a command that produces the object type, such as Get-Item on a file path. If the file defines a named view and you want to select it explicitly, use that view name with the appropriate formatting cmdlet’s -View parameter.

For a new, non-conflicting view definition, load the file with -AppendPath instead. Microsoft documents Update-FormatData and its path parameters in the Update-FormatData cmdlet reference.

Choose precedence and view layout

The path parameter controls how a custom definition relates to existing formatting data. The view layout determines how much information appears and how it is arranged.

Choice Use it when Effect
-PrependPath You intend your definition to take precedence over an existing view. Loads the file ahead of existing definitions, giving the custom definition precedence.
-AppendPath You are adding a definition that does not need to take precedence over an existing view. Loads the file after existing definitions.
Table You want a compact view of selected fields. Shows data in columns.
List You want more room for labeled fields. Shows properties as entries.
Wide You need a dense display of one value. Arranges that value across columns.
Custom You need a tailored display control. Uses the control and layout defined for that view.

A custom view may appear not to override the default if it was appended rather than prepended, if the view does not target the type being formatted, or if another view is explicitly selected. Check the view’s type selection and the command’s formatting behavior before changing the XML again.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Load the file for this session or future sessions

Update-FormatData reloads formatting data into the current session; it does not require restarting PowerShell. A file loaded this way remains in that session, and PowerShell does not provide a way to remove loaded format data there. Start a new session to return to the original formatting data.

To load the file automatically in future sessions, add the command to a PowerShell profile. Find the directory containing the current profile with:

Split-Path -Path $PROFILE -Parent

Open the profile file in that directory and add the appropriate Update-FormatData command, using -PrependPath or -AppendPath as needed. Profile paths can differ by host and user, so use the value of $PROFILE in the environment where you want the customization.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot a view that does not appear

When a file fails to load or PowerShell does not bind the expected view to an object, Microsoft recommends tracing format-file loading and view binding with Trace-Command:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Trace-Command -Name FormatFileLoading,FormatViewBinding -Expression { Get-Item . } -PSHost

Replace Get-Item . with the command that produces the object you are troubleshooting. Use the trace to distinguish a file-loading problem from a mismatch between the view and the object type or selected view.

  • Confirm that the file path passed to Update-FormatData is correct and that the XML is valid.
  • Check that the view targets the type of object actually being formatted.
  • Use -PrependPath if the intent is to take precedence over an existing view.
  • Check whether the command explicitly chooses a different named view or formatting control.
  • If you need to undo a loaded definition, open a new PowerShell session; loaded format data cannot be removed from the current one.

Keep built-in format files intact

PowerShell’s installation directory is available as $PSHOME. Built-in files such as FileSystem.Format.ps1xml can be useful examples, but do not edit them directly. Keep custom formatting files in a separate location so that your changes remain distinct from the installed reference files. Microsoft also documents digitally signing formatting files as a way to protect users who load them; see about_Format.ps1xml.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.