Last active
January 26, 2021 10:40
-
-
Save JohnRoos/5941dd45f6ba3cce937ed42ec7e4545c to your computer and use it in GitHub Desktop.
Creates a file with a specified size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function New-RandomFile { | |
[CmdletBinding()] | |
param ( | |
# Where the file will be created | |
[parameter(Mandatory)] | |
$Path, | |
# Size of file (tip: use 20mb, 1gb etc.) | |
[parameter(Mandatory)] | |
[int64]$Size | |
) | |
Process { | |
try { | |
$byteArray = New-Object byte[] $Size | |
$RandomObject = New-Object -TypeName System.Random | |
$RandomObject.NextBytes($byteArray) | |
[IO.File]::WriteAllBytes($Path,$byteArray) | |
} | |
catch { | |
Throw "Oops. Something went wrong. $_" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment