We have a customer who is moving platforms, and as part of this, I’ve been tasked with testing a lot of various storage configurations. This means lots of utilization of DiskSpd, which is a disk performance benchmarking tool from Microsoft. We could argue about the value of synthetic disk benchmarks, but they are good for testing a variety of disk configurations with a standardized tool for comparing results. It also has the benefit of add the runtime configuration into the results file. So as long as you have your results file, you can know what parameters you ran the test with. (You do have to document your disk configuration–we are using the name of our output file for this).
Anyway, I have a bunch of these files, and I needed to get the data into Excel. Since I was too lazy to figure out how to parse a text file in C#, my first thought was to use some combination of sed, awk, and grep in a bash shell. I reached out to my friend Anthony Nocentino (b|t) about his thoughts on the best way to do this, and he immediately said PowerShell.
When I asked about how to do things I wanted to do with specific bash commands, he mentioned the fact that I could use bash statements that supported standard input and output in PowerShell. The linked blog shows how to do this in Windows, however I wrote all of this code in PowerShell natively on my MacBook Pro.
$path='$InsertYourPathHere' foreach ($file in $files) { $content = get-content $file $command= ($content)|select -first 1 -skip 1 $results= ($content)|grep total -m1|sed 's/"|"/","/g'|sed 's/"total:"//g' $results= $results.split(",") $Output = New-Object -TypeName PSObject -Property @{ FileName = $File.Name Command = $Command TotalBytes = $Results[0].Trim() TotalIOs = $results[1].Trim() MiBperSec = $results[2].Trim() IOPs = $results[3].Trim() AvgLatency = $results[4].Trim() LatStdDev = $results[5].Trim()}| Select-Object FileName,Command,TotalBytes, TotalIOs, MiBperSec, IOPs,AvgLatency,LatStdDev $Output|Export-CSV results.csv -Append