Get-Content bug: A parameter cannot be found that matches parameter name 'Encoding'
Get-Conent with the Encoding parameter works against local file system paths such as this example:
Get-Content -Encoding Byte -Path C:\Users\desktop.ini
However, against a mapped network drive it does not:
Get-Content -Encoding Byte -Path I:\Users\desktop.ini
Get-Content : A parameter cannot be found that matches parameter name 'Encoding'.
At line:1 char:13
+ Get-Content -Encoding Byte -Path I:\Users\desktop.ini
The issue can be re-produced against a non-existing network drive as well.
The behaviour is not expected and the error message is very misleading to users who don`t know what dynamic parameters is, since the same code works against a local path where -Encoding is used.
Eric Jorgensen commented
I got this misleading error when I accidentally fed in a filename with a space at the beginning.
John Bevan commented
Same issue if you use a local path stored as a [System.Uri] instead of a [System.String]