KirkMunro / FormatPx

Better Formatting in PowerShell
Apache License 2.0
73 stars 5 forks source link

FormatPx 1.0.2.3 and earlier prevents several Format-* | Out-* scenarios from working properly #4

Closed KirkMunro closed 9 years ago

KirkMunro commented 9 years ago

Versions 1.0.2.3 and earlier of FormatPx have a flaw that prevents several scenarios where Format-* cmdlets would be piped to Out-* cmdlets from working as expected. Since FormatPx proxies the Format-* cmdlets, and since those proxies return object data rather than format data, scripts written that would pipe format data to Out-* cmdlets (Out-String, Out-File) end up piping object data to those cmdlets instead.

KirkMunro commented 9 years ago

This issue has been fixed in version 1.0.3.4. The solution was to proxy not only Out-Default, but also Out-String, Out-Printer, Out-File and Out-Host. In each of those proxies, if there is __FormatData on the object that is passed in, the proxies will work against the format data instead of the object data. This allows existing scripts that used these cmdlet verbs together in a pipeline to continue to work together.

Note that this change means that if you pipe an object (or objects) with format data to these cmdlets, they will always work against the format data when it is present. If you want to explicitly send the default format to one of the Out-* cmdlets instead, you can do so by adding Format-Default in the pipeline just before your Out-* cmdlet that you are invoking.