Get-FormatData doesn't report formatting data for some types for which formatting data ships with PowerShell.
See original GitHub issueI 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:
- Created 6 years ago
- Comments:21 (20 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes, you are right. I think your code is the correct way.
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-FormatDatacouldn’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-FormatDataunless you specify-PowerShellVersion 5.1.