Skip to content

Instantly share code, notes, and snippets.

@crpb
Last active May 11, 2024 18:50
Show Gist options
  • Save crpb/7afce347f8fb57640248be42ca12d22f to your computer and use it in GitHub Desktop.
Save crpb/7afce347f8fb57640248be42ca12d22f to your computer and use it in GitHub Desktop.
DiskSpd auto download with drive and core cound selection
$DiskSpd = "$PSScriptRoot\DiskSpd\$($Env:PROCESSOR_ARCHITECTURE.ToLower())\diskspd.exe"
if ( -Not ( Test-Path $DiskSpd ) ) {
# Destination will be the directory of the script + 'DiskSpd'
$destdir = "$PSScriptRoot"
$tempdir = "C:\tmp"
New-Item -Type Directory -Path $tempdir -ErrorAction Stop
$file = "DiskSpd.ZIP"
$tempfile = Join-Path -Path "$tempdir" -ChildPath "$file"
Set-Location -Path $tempdir
$repo = "microsoft/diskspd"
$latest = "https://github.com/${repo}/releases/latest"
#Write-Host "$AppName-Updater called with v=$Version`n"
# Check URI for latest release
$request = [System.Net.WebRequest]::Create($latest)
$response = $request.GetResponse()
$redirectedurl = $response.ResponseUri.OriginalString
$latestversion = $redirectedurl.split('/')[-1].Trim('v')
# FILENAME MUSS PASSE! # von woanners..
#$latestfilename = "$AppName-$latestversion-x64.msi"
$downloaduri = $redirectedurl.Replace('tag', 'download') + '/' + $file
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $downloaduri -OutFile $tempfile
$dir = $file.Split('.')[0]
Expand-Archive $tempfile -Force -Destination "$tempdir\$dir"
Remove-Item $tempfile
Move-Item "$tempdir\$dir" -Destination "$destdir\$dir" -Force
Set-Location -Path "$PSScriptRoot"
}
$DiskSpd_log = "$PSScriptRoot\DiskSpd_$(Get-Date -Format FileDateTime).log"
$CoresMax = $((Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors)
Write-Host "CPU Cores available: $CoresMax"
$Cores = Read-Host -Prompt "Choose how many Cores should be used: 1..${CoresMax}"
$Drives = (Get-PsDrive -PsProvider FileSystem |? { $_.Free -gt 0 })
Write-Host "Possible Disks to test on: $($Drives.Name -Join ", ")"
$Drive_selected = Read-Host -Prompt "Enter Drive Name"
$DiskSpd_file = Join-Path -Path ($Drives |Where-Object -Property Name -EQ -Value $Drive_selected).Root -ChildPath diskspd.io.dat
# https://github.com/Microsoft/diskspd/wiki/Command-line-and-parameters x_0
# $DiskSpd_opts = "-t${Cores} -o32 -b4k -r4k -w0 -d120 -Sh -D -L -c5G $DiskSpd_file"
$DiskSpd_opts = "-t${Cores} -o32 -b4k -r4k -w50 -d120 -Sh -D -L -c5G $DiskSpd_file"
$Parms = $DiskSpd_opts.Split(" ")
& "$DiskSpd" $Parms | Set-Content $DiskSpd_log -Force
Remove-Item -Path $DiskSpd_file
Get-Content $DiskSpd_log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment