Skip to content

Get-FormatData: Description of the -PowerShellVersion parameter is lacking and the associated example is misleading #5076

@mklement0

Description

@mklement0

In a nutshell, the -PowerShellVersion parameter is primarily for internal use, to ensure compatibility between older clients and newer servers and the fact that in interactive use you need to specify it with a high enough version numbers has been acknowledged as a bug - see PowerShell/PowerShell#4237

Quoting @lzybkr from PowerShell/PowerShell#4237 (comment):

This extra parameter was added in 5.1 so remoting would work between older clients and newer servers. The format data returned before 5.1 was incomplete and in some ways wrong, e.g. the file system types were returned as FileSystemTypes and it didn't actually work - the real type names were lost.

The bug is that, without use of -PowerShellVersion, local use of Get-Format currently incorrectly assumes that is being called from a pre-v5.1 client in the context of remoting, causing data for certain types not to be returned, notably including System.IO.DirectoryInfo, System.IO.FileInfo, and Microsoft.PowerShell.Commands.MatchInfo

In short: As a workaround for the bug, in Windows PowerShell and in PowerShell Core as of PowerShell Core 7.0.0-preview.6, you must use -PowerShellVersion $PSVersionTable.PSVersion in order to see all local formatting data.

A fix is pending, which will hopefully make it into v7.0: PowerShell/PowerShell#11270

This should be made clear, and Example 5 should be revised to show Get-FormatData -PowerShellVersion $PSVersionTable.PSVersion instead of the current commands with hard-coded version numbers.

The only other example that would make sense is to run the command with any version number lower than 5.1 - it doesn't matter which - in order to see the formatting data that a pre-v5.1 client would see during remoting; e.g., Get-FormatData -PowerShellVersion 5.0.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Labels

area-utilityArea - Microsoft.PowerShell.Utility module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions