question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get-FormatData doesn't report formatting data for some types for which formatting data ships with PowerShell.

See original GitHub issue

I haven’t looked into the logic behind which types’ formatting data isn’t being reported, but two examples are below.

A counter example is Get-FormatData System.Management.Automation.AliasInfo, which works as expected.

Steps to reproduce

Get-FormatData System.IO.DirectoryInfo, System.IO.FileInfo

Expected behavior

[System.Management.Automation.ExtendedTypeDefinition] instances describing the formatting, as usual.

Actual behavior

No output is produced; $? indicates $True.

Yet, formatting data is clearly in effect.

In Windows PowerShell, it can be discovered as follows:

Select-String -List System.IO.DirectoryInfo, System.IO.FileInfo $PSHOME/*.ps1xml 

Environment data

PowerShell Core v6.0.0-beta.3 on macOS 10.12.5
PowerShell Core v6.0.0-beta.3 on Ubuntu 16.04.1 LTS
PowerShell Core v6.0.0-beta.3 on Microsoft Windows 10 Pro (64-bit; v10.0.14393)
Windows PowerShell v5.1.15063.413 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:21 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
PaulHigincommented, Nov 26, 2019

Yes, you are right. I think your code is the correct way.

1reaction
lzybkrcommented, Jul 25, 2017

In the abstract - some format data properties were missing before 5.1. If those properties were non-null, then the format data returned by Get-FormatData couldn’t have been used correctly, so those types are not returned.

To be concrete, look at the implementations of PSControl.CompatibleWithOldPowerShell

Briefly, I think GroupBy, SelectCondition, and CustomControl are the items that trigger not getting returned by Get-FormatData unless you specify -PowerShellVersion 5.1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get-FormatData (Microsoft.PowerShell.Utility)
The Get-FormatData cmdlet gets the formatting data in the current session. The formatting data in the session includes formatting data from Format.ps1xml ...
Read more >
Loading and Exporting Formatting Data - PowerShell
You can export the format data for a type to a file using the Export-FormatData cmdlet.
Read more >
Using Format commands to change output view - PowerShell
This article describes the Format-Wide , Format-List , and Format-Table cmdlets. Each object type in PowerShell has default properties that are ...
Read more >
Stream powershell output objects to format-table
Associate predefined formatting data with the .NET type of your output objects and define a table view with fixed column widths.
Read more >
Formatting, aliases, providers, comparison - PowerShell
This chapter introduces the concepts of output formatting, command aliases, providers, and comparison operations.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found