speedtest.ps1 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. ## Measures the speed of the download, can only be ran on a PC running Windows 10 or a server running Server 2016+, plan is to add uploading also
  2. ## Majority of this script has been copied/butchered from https://www.ramblingtechie.co.uk/2020/07/13/internet-speed-test-in-powershell/
  3. # MINIMUM ACCEPTED THRESHOLD IN mbps
  4. $mindownloadspeed = 10
  5. $minuploadspeed = 0.5
  6. # File to download you can find download links for other files here https://speedtest.flonix.net
  7. $downloadurl = "http://services.am-networks.fr/jirafeau/f.php?h=1AJKnNts&d=1"
  8. #$UploadURL = "http://ipv4.download.thinkbroadband.com/10MB.zip"
  9. # SIZE OF SPECIFIED FILE IN MB (adjust this to match the size of your file in MB as above)
  10. $size = 20
  11. # Name of Downloaded file
  12. $localfile = "SpeedTest.bin"
  13. # WEB CLIENT VARIABLES
  14. $webclient = New-Object System.Net.WebClient
  15. #RUN DOWNLOAD & CALCULATE DOWNLOAD SPEED
  16. $downloadstart_time = Get-Date
  17. $webclient.DownloadFile($downloadurl, $localfile)
  18. $downloadtimetaken = $((Get-Date).Subtract($downloadstart_time).Seconds)
  19. $downloadspeed = ($size / $downloadtimetaken)*4
  20. Write-Output "Time taken: $downloadtimetaken second(s) | Download Speed: $downloadspeed mbps"
  21. #RUN UPLOAD & CALCULATE UPLOAD SPEED
  22. #$uploadstart_time = Get-Date
  23. #$webclient.UploadFile($UploadURL, $localfile) > $null;
  24. #$uploadtimetaken = $((Get-Date).Subtract($uploadstart_time).Seconds)
  25. #$uploadspeed = ($size / $uploadtimetaken) * 8
  26. #Write-Output "Time taken: $uploadtimetaken second(s) | Upload Speed: $uploadspeed mbps"
  27. #DELETE TEST DOWNLOAD FILE
  28. Remove-Item -path $localfile
  29. #SEND ALERTS IF BELOW MINIMUM THRESHOLD
  30. if ($downloadspeed -ge $mindownloadspeed)
  31. {
  32. Write-Output "Speed is acceptable. Current download speed at is $downloadspeed mbps which is above the threshold of $mindownloadspeed mbps"
  33. exit 0
  34. }
  35. else
  36. {
  37. Write-Output "Current download speed at is $downloadspeed mbps which is below the minimum threshold of $mindownloadspeed mbps"
  38. exit 1
  39. }
  40. Exit $LASTEXITCODE