Last active
March 20, 2018 02:51
-
-
Save pwmcintyre/44442546fd98d3239616a8271c1ae60d to your computer and use it in GitHub Desktop.
PowerShell - Continuously write random data to a disk
This file contains 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
# 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