-
Notifications
You must be signed in to change notification settings - Fork 15
/
test-csv.ps1
62 lines (44 loc) · 1.5 KB
/
test-csv.ps1
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# running with PowerShell 7+
# open powershell in your terminal in this folder and type ".\test"
#options
$outputfile = ".\internetspeed.csv" #CSV file where the test results are stored
$testduration = 14 #in days
$interval = 1 #wait and restart after $interval seconds
$numberoftests = $testduration*24*60*60/$interval #calculated based on $testduration and the $interval
#execution
Write-Host "Running test every " $interval "seconds"
Write-Host "Tests to run:" $numberoftests
Write-Host "Writing test results to a file:"$outputfile
Write-Host ""
#$OutArray = @()
if (-not(Test-Path -Path $outputfile -PathType Leaf)) {
#write headers on first launch
$content = Get-Content ".\src\templates\headers.csv.tpl"
$content | Set-Content $outputfile
}
$failed = 0
for($i = 0; $i -lt $numberoftests; $i++){
try{
Write-Host "---"
Write-Host "Running test #"$($i+1)
#running speedtest
$response = .\speedtest --format=csv --unit=Mbps
#$responseObj = $response | ConvertFrom-Json
if ($response -Match "result") {
#adjusting JSON formatting
$response | Out-File -FilePath $outputfile -Append -Encoding utf8
Write-Host "Test #"$($i+1)"completed"
}
else {
Write-Error "Error"
$failed+=1
}
}
catch{
#catch error
}
Write-Host "Total tests:" $($i+1) "(failed" $failed")"
Write-Host "---"
Write-Host ""
Start-Sleep -Seconds $interval
}