How to Generate Large Files using PowerShell

Table of Contents

Generate Large Files using PowerShell

Why we need to generate large files. Below are some situations you may need them:

  • Use dummy files to figure out if there are any bad sectors on your hard drive.
  • Testing your network speed.
  • Ensure that files on your computer or device are deleted beyond recovery and etc.

Regardless of your reasons, here are the ways to create such files in any modern version of Windows. You can find some small and free tools from internet do it. But in this post, we’ll show how to create them with PowerShell or PowerShell Core quickly.

Create a dummy file with the fsutil

All Windows versions since Vista include an executable named fsutil.exe. You can find it in the system folder. This is the native tool from Microsoft. So, we can use it with no risk.

PS C:> Get-Command fsutil | Format-List

Name            : fsutil.exe
CommandType     : Application
Definition      : C:Windowssystem32fsutil.exe
Extension       : .exe
Path            : C:Windowssystem32fsutil.exe
FileVersionInfo : File:             C:Windowssystem32fsutil.exe
                  InternalName:     fsutil.exe
                  OriginalFilename: fsutil.exe.mui
                  FileVersion:      10.0.22621.2361 (WinBuild.160101.0800)
                  FileDescription:  fsutil.exe
                  Product:          Microsoft® Windows® Operating System
                  ProductVersion:   10.0.22621.2361

For example, we’ll create a zip file with 10GB in sise. The size can be in KB, GB and TB.

fsutil file createNew "C:temptest1.zip" (10GB)
How to Generate Large Files using PowerShell

Create a large file using PowerShell with .Net

The second way, we can create a dummy file using .Net as follows:

$path = "C:temptest.zip"
$size = 1GB
$content = New-Object byte[] $size
(New-Object System.Random).NextBytes($content)
[System.IO.File]::WriteAllBytes($path, $content)
How to Generate Large Files using PowerShell

The different between two methods is the files created with fsultil are empty. For example, we’ll create two small text files as below:

fsutil file createNew "C:temptest1.txt" (1MB)

$path = "C:temptest.txt"
$size = 1MB
$content = New-Object byte[] $size
(New-Object System.Random).NextBytes($content)
[System.IO.File]::WriteAllBytes($path, $content)

As you can see in the below screenshot, the text file created by fsulti is empty.

How to Generate Large Files using PowerShell

Create multiple dummy files using PowerShell

In case you want to create multiple large files. You can use the for loop in PowerShell to create them. For example, we create eight files with 15GB in size and the file named randomly.

for ($i = 2; $i -lt 10; $i++) {
    fsutil file createNew "C:temptest-$(Get-Random).zip" (15GB)
}
How to Generate Large Files using PowerShell

Leave a Comment

Required fields are marked *