Skip to content

Instantly share code, notes, and snippets.

@JohnRoos
Last active January 26, 2021 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnRoos/5941dd45f6ba3cce937ed42ec7e4545c to your computer and use it in GitHub Desktop.
Save JohnRoos/5941dd45f6ba3cce937ed42ec7e4545c to your computer and use it in GitHub Desktop.
Creates a file with a specified size
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