Files
management-scripts/Test-InternetBandwidth.ps1
T

62 lines
2.5 KiB
PowerShell
Raw Normal View History

2021-07-29 12:36:52 -04:00
## Specify URL to SpeedTest CLI app
$URL = 'https://install.speedtest.net/app/cli/ookla-speedtest-1.0.0-win64.zip'
## Download the app from the URL
$ZIPFILE = Download-File -URL $URL
## Setup the directory to extract the downloaded zip file to
$WORKINGDIR = $ZIPFILE.Substring(0, $ZIPFILE.LastIndexOf('.'))
If ( Test-Path $WORKINGDIR ) {
LogMsg "Deleting existing directory: ""$WORKINGDIR"""
Try { Remove-Item -Path $WORKINGDIR -Recurse -Force }
Catch { LogErr $_.Exception.Message }
}
LogMsg "Creating new directory: ""$WORKINGDIR"""
Try { New-Item -Path $WORKINGDIR -ItemType Directory -Force | Out-Null }
Catch { LogErr $_.Exception.Message }
## Extract $ZIPFILE to $WORKINGDIR
Try {
2021-10-23 09:33:00 -04:00
Add-Type -Assembly System.IO.Compression.FileSystem
2021-07-29 12:36:52 -04:00
[IO.Compression.ZipFile]::ExtractToDirectory($ZIPFILE, $WORKINGDIR)
}
Catch { LogErr $_.Exception.Message }
## Run the SpeedTest CLI app
$SPEEDTEST = "${WORKINGDIR}\speedtest.exe"
If ( Test-Path $SPEEDTEST ) {
Try {
2021-10-23 13:53:31 -04:00
LogMsg "Starting internet bandwidth test"
2021-10-23 09:33:00 -04:00
$RESULTS = [string]( cmd.exe /c ""${SPEEDTEST} --accept-license --progress=no"" )
## Cleanup the output
If ( -not [string]::IsNullOrEmpty($RESULTS) ) {
$RESULTS = $RESULTS -replace "Server: ", "`n`nServer: "
$RESULTS = $RESULTS -replace "ISP: ", "`nISP: "
$RESULTS = $RESULTS -replace "Latency: ", "`nLatency: "
$RESULTS = $RESULTS -replace "Download: ", "`nDownload: "
$RESULTS = $RESULTS -replace "Upload: ", "`nUpload: "
$RESULTS = $RESULTS -replace "Packet Loss: ", "`nPacket Loss: "
$RESULTS = $RESULTS -replace "Result URL: ", "`nResult URL: "
$RESULTS = $RESULTS + "`n"
} Else { $RESULTS = "The test did not product any output" }
LogMsg $RESULTS
2021-10-23 13:53:31 -04:00
LogMsg "Finished internet bandwidth test"
}
2021-07-29 12:36:52 -04:00
Catch { LogErr $_.Exception.Message }
2021-10-23 09:33:00 -04:00
2021-07-29 12:36:52 -04:00
} Else { LogMsg "The file does not exist at the expected path: ""${SPEEDTEST}""" }
## Cleanup files and directories created by this script
If ( Test-Path $ZIPFILE ) {
LogMsg "Deleting downloaded zip file: ""$ZIPFILE"""
Try { Remove-Item -Path $ZIPFILE -Force }
Catch { LogErr $_.Exception.Message }
} Else { LogMsg "Downloaded zip file no longer exists: ""$ZIPFILE""" }
If ( Test-Path $WORKINGDIR ) {
LogMsg "Deleting directory from extracted zip file: ""$WORKINGDIR"""
Try { Remove-Item -Path $WORKINGDIR -Recurse -Force }
Catch { LogErr $_.Exception.Message }
} Else { LogMsg "Directory from extracted zip file no longer exists: ""$WORKINGDIR""" }