Skip to content

Instantly share code, notes, and snippets.

@jwmoss
Last active August 14, 2025 20:13
Show Gist options
  • Save jwmoss/b9a3bd1c5ff8c2bd4add97c598909f94 to your computer and use it in GitHub Desktop.
Save jwmoss/b9a3bd1c5ff8c2bd4add97c598909f94 to your computer and use it in GitHub Desktop.

Revisions

  1. jwmoss revised this gist Aug 14, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion speed_d.ps1
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    # --- Settings ---
    $diskspdUrl = "https://github.com/microsoft/diskspd/releases/download/v2.2/DiskSpd.ZIP"
    $diskspdExe = "$env:TEMP\diskspd.exe"
    $tempFile = "$env:TEMP\diskspd_testfile.dat"
    $tempFile = "D:\diskspd_testfile.dat" # test file now on D:
    $outFile = "$env:TEMP\diskspd_results.txt"

    $fileSize = "1G" # test file size
  2. jwmoss revised this gist Aug 14, 2025. No changes.
  3. jwmoss revised this gist Aug 14, 2025. No changes.
  4. jwmoss created this gist Aug 14, 2025.
    65 changes: 65 additions & 0 deletions speed_d.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    # Test C: drive speed with DiskSpd (fixed arg passing)

    # --- Settings ---
    $diskspdUrl = "https://github.com/microsoft/diskspd/releases/download/v2.2/DiskSpd.ZIP"
    $diskspdExe = "$env:TEMP\diskspd.exe"
    $tempFile = "$env:TEMP\diskspd_testfile.dat"
    $outFile = "$env:TEMP\diskspd_results.txt"

    $fileSize = "1G" # test file size
    $duration = 30 # seconds
    $threads = 4

    # --- Download DISKSPD if not found ---
    if (-not (Test-Path $diskspdExe)) {
    Write-Host "Downloading DISKSPD..."
    $zip = Join-Path $env:TEMP "diskspd.zip"
    Invoke-WebRequest -Uri $diskspdUrl -OutFile $zip

    Expand-Archive -Path $zip -DestinationPath $env:TEMP -Force
    Remove-Item $zip -Force

    # Find the right exe (prefer amd64/x64)
    $exeFound = Get-ChildItem -Path $env:TEMP -Filter "diskspd.exe" -Recurse |
    Sort-Object { if ($_.FullName -match 'amd64|x64') {0} else {1} } |
    Select-Object -First 1
    if ($exeFound) {
    Copy-Item $exeFound.FullName $diskspdExe -Force
    } else {
    Write-Error "DISKSPD executable not found after extraction."
    exit 1
    }
    }

    # --- Run Test ---
    Write-Host "Running DISKSPD test on C: drive..."

    # Build argument list explicitly so variables interpolate correctly
    $args = @(
    "-c$($fileSize)"
    "-d$($duration)"
    "-Sh"
    "-L"
    "-b64K"
    "-t$($threads)"
    "-o4"
    "-w50"
    $tempFile
    )

    try {
    & $diskspdExe @args | Tee-Object -FilePath $outFile
    $code = $LASTEXITCODE
    }
    finally {
    if (Test-Path $tempFile) { Remove-Item $tempFile -Force }
    }

    Write-Host "`n=== DISKSPD Results ==="
    if (Test-Path $outFile) {
    Get-Content $outFile
    } else {
    Write-Warning "No results file was produced (DiskSpd likely failed before writing output)."
    }

    if ($code) { exit $code } else { exit 0 }