Skip to content

Instantly share code, notes, and snippets.

@pwmcintyre
Last active March 20, 2018 02:51
Show Gist options
  • Save pwmcintyre/44442546fd98d3239616a8271c1ae60d to your computer and use it in GitHub Desktop.
Save pwmcintyre/44442546fd98d3239616a8271c1ae60d to your computer and use it in GitHub Desktop.
PowerShell - Continuously write random data to a disk
# running this will consume 10GB of data in the target path
# use SIGINT to stop (Ctrl + C)
function Run {
Param(
[ValidateNotNullOrEmpty()]
[string]$Target
)
New-Item -Path $Target -Type directory -Force
$count = 0
while ($True) {
$count++
$count %= 10000 # prevent filling up the disk
$out = new-object byte[] 1048576
(new-object Random).NextBytes($out)
$time = Get-Date -Format o
$duration = Measure-Command {
try {
[IO.File]::WriteAllBytes((Join-Path $Target "file-$count.dat"), $out)
} catch {}
}
Write-Output "$time`t$count`t$duration"
}
}
try {
$start = Get-Date -Format yyyyMMddTHHmmssffffZ
Start-Transcript -Path "./writetest-$start.txt"
Run -Target (Join-Path '/tmp' 'test')
} finally {
Stop-Transcript
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment