Code Snippet

Create A Random File Using Powershell

  • Posted on: 21 August 2014
  • By: Nate Jones

I recently needed to create a file for testing the upload capabilities on a website. The content of the file didn't matter, only the size. So I wrote this little powershell script to dump a random series of bytes to disk.

  1. #Create the array of the size you want
  2. $out = New-Object Byte[] 1024
  3. #Fill the array using a System.Random object
  4. (New-Object Random).NextBytes($out)
  5. #Write the array to a file with System.IO.File
  6. [IO.File]::WriteAllBytes('filename', $out)