Skip to content

Instantly share code, notes, and snippets.

@breeze4
Created November 24, 2022 04:25
Show Gist options
  • Save breeze4/a59dcb402f5299a2e6c384120d1aec60 to your computer and use it in GitHub Desktop.
Save breeze4/a59dcb402f5299a2e6c384120d1aec60 to your computer and use it in GitHub Desktop.
Powershell speedtest
# this is cribbed from here, but without the emailing - just prints out the results:
# https://community.spiceworks.com/scripts/show/4910-remotely-or-locally-run-a-speed-test-via-powershell
# https://www.speedtest.net/apps/cli
cls
$DownloadURL = "https://install.speedtest.net/app/cli/ookla-speedtest-1.0.0-win64.zip"
#location to save on the computer. Path must exist or it will error
$DOwnloadPath = "c:\temp\SpeedTest.Zip"
$ExtractToPath = "c:\temp\SpeedTest"
$SpeedTestEXEPath = "C:\temp\SpeedTest\speedtest.exe"
#Log File Path
$LogPath = 'c:\temp\SpeedTestLog.txt'
#Start Logging to a Text File
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path $LogPath -Append:$false
#check for and delete existing log files
function RunTest()
{
$test = & $SpeedTestEXEPath --accept-license
$test
}
#check if file exists
if (Test-Path $SpeedTestEXEPath -PathType leaf)
{
Write-Host "SpeedTest EXE Exists, starting test" -ForegroundColor Green
RunTest
}
else
{
Write-Host "SpeedTest EXE Doesn't Exist, starting file download"
#downloads the file from the URL
wget $DownloadURL -outfile $DOwnloadPath
#Unzip the file
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
param([string]$zipfile, [string]$outpath)
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}
Unzip $DOwnloadPath $ExtractToPath
RunTest
}
echo "Preparing results"
#get hostname
$Hostname = hostname
#read results out of log file into string
$Data = (Get-Content -Path $LogPath) -join "`n"
#prints results use log file string as body
echo $Data
#stop logging
Stop-Transcript
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment