Wednesday, December 18, 2019

When Get-Content doesn't recognize the -Encoding parameter

PowerShell's Get-Content cmdlet can read NTFS alternate data streams either with the -Stream parameter or by putting the stream after a colon in the path. Using the latter approach and trying to get the data of a file in the current directory as a byte array, someone mentioned that they received an error saying "a parameter cannot be found that matches parameter name 'Encoding'". This turned out to be because the path wasn't being interpreted as a file system path because it wasn't qualified - the .\ was missing. So the file system provider wasn't being used, and apparently that provider is responsible for some dynamic parameters like -Encoding. Qualifying the path fixed the problem.

No comments:

Post a Comment