Search notes:

System.Text.Encoding - GetBytes()

GetBytes() (a static method of System.Text.Encoding) converts a string to a byte array.
The following script prints different output, depending the encoding of the file and if it is run with PowerShell 5 or PowerShell 7
$enc_utf_8   = [System.Text.Encoding]::GetEncoding('utf-8'     )
$enc_latin_1 = [System.Text.Encoding]::GetEncoding('iso-8859-1')

write-host 'Bytes in UTF-8'
foreach ($b in $enc_utf_8.GetBytes('René')) {
   write-host "  $b"
}
write-host 'Bytes in Latin-1'
foreach ($b in $enc_latin_1.GetBytes('René')) {
   write-host "  $b"
}
For the following conditions: the output is:
Bytes in UTF-8
  82
  101
  110
  195
  169
Bytes in Latin-1
  82
  101
  110
  233
For the following conditions the output is
Bytes in UTF-8
  82
  101
  110
  195
  131
  194
  169
Bytes in Latin-1
  82
  101
  110
  195
  169
For the following conditions
Bytes in UTF-8
  82
  101
  110
  239
  191
  189
Bytes in Latin-1
  82
  101
  110
  63

See also

System.Text.Encoding

Index