Get the first n characters of a large file with PowerShell

Question:

I’ve got a huge XML file (0.5 GB), with no line breaks. I want to be able to look at, say, the first 200 characters without opening the whole file. Is there a way to do this with PowerShell?

Answer:

PowerShell Desktop (up to 5.1)

You can read at the byte level with Get-Content like so:

If the log file is ASCII you can simplify this to:

PowerShell Core 6.0 and newer

PowerShell Core doesn’t support byte encoding. It’s been replaced by -AsByteStream parameter.

Source:

Get the first n characters of a large file with PowerShell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply