O'Reilly logo

Pro Windows PowerShell by Hristo Deshev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

15.4. Getting Byte Content

The most powerful way to work with a file's contents is to get it as a byte array. That grants you the ability to change every single bit in the file and turn it into whatever you wish. Let's now save a file as an ASCII character sequence and get its byte values:

PS> "aaaa" | Set-Content -Encoding Ascii -Path ascii.txt
PS> Get-Content .\ascii.txt -Encoding Byte
97
97
97
97
13
10

We are using the sample sequence of "aaaa", so that we can easily distinguish it in the byte sequence we get back. As you can see from the results, our file contains 6 bytes: the four "a" characters plus two characters with the 10 and 13 character codes, respectively. The 10 code corresponds to the carriage return symbol, and the 13 to the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required