Generate large files using PowerShell
- Gérald Barré
If you need to create a large file with random data for testing purpose, you can use PowerShell or PowerShell Core to quickly generate it.
$path = Join-Path $pwd "test.txt" $size = 1GB $content = New-Object byte $size (New-Object System.Random).NextBytes($content) # Set-Content is very slow, use .NET method directly [System.IO.File]::WriteAllBytes($path, $content)
If you want an empty file (fill with zeros) instead and you are on Windows, you can use
$size = 1GB fsutil file createNew test.txt $size
Do you have a question or a suggestion about this post? Contact me!
Enjoy this blog?💖 Sponsor on GitHub