Table of Contents
Create a Dummy File of Any Size with 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:\Windows\system32\fsutil.exe
Extension : .exe
Path : C:\Windows\system32\fsutil.exe
FileVersionInfo : File: C:\Windows\system32\fsutil.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:\temp\test.txt" (1MB)
Create a large file using PowerShell with .Net
The second way, we can create a dummy file using .Net as follows:
$path = "C:\temp\test.zip"
$size = 1GB
$content = New-Object byte[] $size
(New-Object System.Random).NextBytes($content)
[System.IO.File]::WriteAllBytes($path, $content)
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:\temp\test1.txt" (1MB)
$path = "C:\temp\test.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.
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.
Create ten files with 10MB in size and the file named formatted as test0.zip, test1.zip, test2.zip…
for ($i = 0; $i -lt 10; $i++) {
fsutil file createNew "C:\temp\test$i.zip" (10MB)
}
Create ten files with 15MB in size and the file named randomly.
for ($i = 0; $i -lt 10; $i++) {
fsutil file createNew "C:\temp\test-$(Get-Random).zip" (15MB)
}
Create multiple dummy files with the file name based on the created date and time.
for ($i = 1; $i -lt 10; $i++) {
fsutil file createNew "test_$((Get-Date -format MMM-dd` hh-mm-ss` tt).ToString()).zip" (10MB)
Start-Sleep -Milliseconds 900
}
Not a reader? Watch this related video tutorial: