Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

powershell to get the first x MB of a file

Tags:

powershell

Its pretty straightforward to get the first x lines of a text file, but I need the first x MB of a file. Given that I'm a PowerShell neophyte if you could please give me some annotations on the script that would be greatly appreciated.

like image 678
Ralph Shillington Avatar asked May 20 '09 13:05

Ralph Shillington


1 Answers

Get-Content foo.exe -TotalCount 1MB -Encoding byte

If you happen to be using PowerShell Community Extensions then do this:

Format-Hex foo.exe -count 1MB

Note: If you are using PowerShell V2 be sure to grab the 1.2 beta of PSCX.

like image 127
Keith Hill Avatar answered Oct 14 '22 10:10

Keith Hill