I found some even more promising options:
I was able to make the first one work with barely any changes, but the results are not accurate. The second one needs to be tortured a bit to make it suitable since emits live status data, but again, running it from the CLI it is not accurate. The only CLI option I have found that is accurate is speedtest-cli (Python). Looking at both the above to see how hard they would be to rewrite into Groovy and make accurate.
My current iteration of the original code is below (for now), but this method is also not very accurate. It relies on two properties, one optional:
speedtest.run: set to 1 (or anything) for hosts that should run the code (may instead use manual instances to enable multiple test sources).
speedtest.testmy.mirror: shortname of the testmy.net mirror (e.g., lax, ny, etc.). if not provided, will use default mirror selection.
$size = 50;
$mirror = "##speedtest.testmy.mirror##";
if ($site -eq "") {
$url = "https://testmy.net/dl-${size}MB"
}
else {
$url = "https://${mirror}.testmy.net/dl-${size}MB"
}
$path = "Out-Null"
$WebClient = New-Object System.Net.WebClient
$mbps = "{0:N2}" -f (($size/(Measure-Command {$Request=Get-Date; $WebClient.DownloadFile( $url, $path )}).TotalSeconds) * 8)
Write-Host "Mbps="$mbps