Last active
June 4, 2024 00:27
-
-
Save crpb/7afce347f8fb57640248be42ca12d22f to your computer and use it in GitHub Desktop.
DiskSpd auto download with drive and core cound selection
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
$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 = "$env:TEMP" | |
New-Item -Type Directory -Path $tempdir -ErrorAction Ignore | |
$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') | |
$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" | |
if (!($Cores = Read-Host -Prompt "Choose how many Threads/Cores should be used - 1..${CoresMax} or more..: [1]")) { $cores = 1 } | |
if (!($Duration = Read-Host -Prompt "Duration in sec. [120]")) { $Duration = 120 } | |
if (!($ReadWrite = Read-Host -Prompt "Read/Write ratio? 0=100% read, 100=100% write, 50=50/50: [0]")) { $ReadWrite = 0 } | |
if (!($FileSize = Read-Host -Prompt "File size: [5G]")) { $FileSize = "5G" } | |
$Drives = (Get-PsDrive -PsProvider FileSystem |? { $_.Free -gt 0 }) | |
Write-Host "Possible Disks: $($Drives.Name -Join ", ")" | |
if (!($Drive_selected = Read-Host -Prompt "Enter Drive Name: [C]")) { $Drive_selected = "C" } | |
$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 -w$ReadWrite -d$Duration -Sh -D -L -c$FileSize $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