Error “Get-Content: Cannot process argument transformation on parameter ‘Encoding’. ‘byte’”

You receive the following error message when you try to read a certificate file using PowerShell 7.1.3.

Error Message

The entire error message is shown below.

Get-Content: Cannot process argument transformation on parameter 'Encoding'. 'byte' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. (Parameter 'name')

The PowerShell cmdlet used when receiving the error message is:

## Replace the file path with the location of your certificate

[convert]::ToBase64String((Get-Content cert.cer -Encoding byte))  | Out-File -FilePath "key.txt"

Solution

To fix the issue and run the cmdlet successfully, first, make sure you use PowerShell 7 and change the cmdlet to:/

[convert]::ToBase64String((Get-Content "cert.cer" -AsByteStream -Raw ))  | Out-File -FilePath "key.txt"


Posted

in

,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.