Creating large test file on Windows

gsndev 21 Reputation points
2021-07-28T19:04:26.207+00:00

I'm planning to monitor the network with a large file transfer and need to create a dummy test file on Windows. Please can I get a confirmation if creating a test file using fsutil is recommended for this task?
fsutil file createnew pathfilename size

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,615 questions
{count} votes

Accepted answer
  1. Andreas Baumgarten 109.1K Reputation points MVP
    2021-07-28T19:58:54.54+00:00

    Hi @gsnarendran-4128 ,

    fsutil is a good option to create a large file.

    I am using the following script for the same task:

    $file = new-object System.IO.FileStream c:\temp\testfile.bin, Create, ReadWrite
    $file.SetLength(4GB)
    $file.Close()
    

    if you prefer a file with random content you can this this:

    $file = "c:\temp\testfile3.bin"
    $sizeInMB = 8
    $out = new-object byte[] ($sizeInMB*1048576); (new-object Random).NextBytes($out); [IO.File]::WriteAllBytes($file, $out)
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. NetoMeter 1 Reputation point
    2021-07-28T20:18:55.567+00:00

    I like Andreas' solution as nowadays, using PS is the preferred approach. There is nothing wrong with using fsutil - you will have to specify the size in bytes though:

    fsutil file createNew C:\Temp\testfile.bin 4294967296


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.