-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Get-FormatData: Description of the -PowerShellVersion parameter is lacking and the associated example is misleading #5076
Description
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.
- ID: 4ce9dd6f-06b2-1fb1-589c-0472739a839b
- Version Independent ID: 9cfff0f3-2005-08f5-d0d4-6c3897d0c3ce
- Content: Get-FormatData (Microsoft.PowerShell.Utility)
- Content Source: reference/7/Microsoft.PowerShell.Utility/Get-FormatData.md
- Product: powershell
- Technology: powershell-cmdlets
- GitHub Login: @JamesWTruher
- Microsoft Alias: jimtru