Home Powershell Speedtest
Post
Cancel

Powershell Speedtest

Was having problems with my internet connection and wanted to monitor it. So I rewrote this script to use powershell and store the results in a table storage.

The script is using the speedtest cli from https://www.speedtest.net/apps/cli

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#$StorageAccountName = "StorageAcount"
#$Key = "Storagekey"
#$StorageContext = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $Key
#$Table = (Get-AzStorageTable -Context $StorageContext | Where-Object {$_.name -eq "Speedtest"}).CloudTable
$applocation = "C:\apps\speedtest"
$path = "C:\temp\"

$SpeedTestResults=@()
$SpeedtestObj=@()

$i = 0
while ($i -eq 0)
{
    $PartitionKey = "1"
    $SpeedTestResults = & "$($applocation)\speedtest.exe" --progress=no --format=json
    $SpeedtestResults = $SpeedTestResults | ConvertFrom-Json
    $SpeedtestObj += [PSCustomObject] @{
        Time = Get-Date -Format "dd/MM/yyyy HH:mm K"
        downloadspeed = [math]::Round($SpeedtestResults.download.bandwidth / 1000000 * 8, 2)
        uploadspeed   = [math]::Round($SpeedtestResults.upload.bandwidth / 1000000 * 8, 2)
        packetloss    = ($($SpeedtestResults.packetLoss).ToString("P"))
        isp           = $SpeedtestResults.isp
        ExternalIP    = $SpeedtestResults.interface.externalIp
        InternalIP    = $SpeedtestResults.interface.internalIp
        UsedServer    = $SpeedtestResults.server.host
        location      = $SpeedTestResults.server.location
        Jitter        = [math]::Round($SpeedtestResults.ping.jitter)
        Latency       = [math]::Round($SpeedtestResults.ping.latency)       
    }
    # ---- Move to table storage ----
    # Add-AzTableRow -table $Table -PartitionKey $PartitionKey -RowKey (Get-Date).Ticks -property $SpeedtestObj
   
    Start-Sleep -Seconds 15
}
#$SpeedtestObj | Format-Table | Out-String|ForEach-Object {Write-Host $_}
$SpeedtestObj | Export-Csv -Path $path\speedtest.csv -NoTypeInformation
TimedownloadspeeduploadspeedpacketlossispExternalIPInternalIPUsedServerlocationJitterLatency
07.04.2023 12:40 +00:00 938,14 941,96 0,00% Mila hf 157.157.x.x 192.168.x.x speedtest.siminn.is Reykjavik 0 1
07.04.2023 12:40 +00:00 935,38 943,01 0,00% Mila hf 157.157.x.x 192.168.x.x speedtest.siminn.is Reykjavik 0 1
07.04.2023 12:40 +00:00 935,65 935,06 0,00% Mila hf 157.157.x.x 192.168.x.x speedtest.siminn.is Reykjavik 0 1
07.04.2023 12:42 +00:00 936,81 942,66 0,00% Mila hf 157.157.x.x 192.168.x.x speedtest.siminn.is Reykjavik 0 1
07.04.2023 12:43 +00:00 905,52 813,36 0,00% Mila hf 157.157.x.x 192.168.x.x speedtest.hringidan.is Reykjavik 0 1
07.04.2023 12:43 +00:00 937,37 933,34 0,00% Mila hf 157.157.x.x 192.168.x.x speedtest.siminn.is Reykjavik 0 1
07.04.2023 12:44 +00:00 936,46 941,38 0,00% Mila hf 157.157.x.x 192.168.x.x speedtest.siminn.is Reykjavik 0 1
07.04.2023 12:44 +00:00 934,13 940,8 0,00% Mila hf 157.157.x.x 192.168.x.x speedtest1.nova.is Reykjavik 0 1
07.04.2023 12:47 +00:00 935,56 940,52 0,00% Mila hf 157.157.x.x 192.168.x.x speedtest.siminn.is Reykjavik 0 1
07.04.2023 12:47 +00:00 907,63 927,59 0,00% Mila hf 157.157.x.x 192.168.x.x speedtest.hringidan.is Reykjavik 0 1
07.04.2023 12:47 +00:00 934,07 937,97 0,00% Mila hf 157.157.x.x 192.168.x.x speedtest1.nova.is Reykjavik 0 1
07.04.2023 12:48 +00:00 938,24 940,33 0,00% Mila hf 157.157.x.x 192.168.x.x speedtest.siminn.is Reykjavik 0 1
07.04.2023 12:48 +00:00 928,74 937,43 0,00% Mila hf 157.157.x.x 192.168.x.x speedtest.siminn.is Reykjavik 0 1
07.04.2023 12:49 +00:00 934,5 942,71 0,00% Mila hf 157.157.x.x 192.168.x.x speedtest.siminn.is Reykjavik 0 1
07.04.2023 12:49 +00:00 932,9 936,99 0,00% Mila hf 157.157.x.x 192.168.x.x speedtest.siminn.is Reykjavik 0 1
This post is licensed under CC BY 4.0 by the author.