Skip to content

Instantly share code, notes, and snippets.

@trstringer
Last active June 1, 2022 20:07
Show Gist options
  • Save trstringer/adcc68d682c08ffab74c to your computer and use it in GitHub Desktop.
Save trstringer/adcc68d682c08ffab74c to your computer and use it in GitHub Desktop.
The steps to routinely (looping) check local to internet performance
Write-Warning "This code is not meant to be run sequentially, run it in sections following comment instructions"
exit
<##############################################################################
create transfer file
##############################################################################>
$FilePath = "C:\temp\transfer_file.txt"
$DesiredFileSizeKB = 1024 * 7 # 7 MB
if (Test-Path $FilePath) {
Remove-Item $FilePath
}
do {
"Better living through programming" |
Out-File $FilePath -Append
} while ((
Get-ChildItem $FilePath |
Select-Object @{Name = "SizeKB"; Expression = { $_.Length / 1024 }} |
Select-Object -ExpandProperty SizeKB) -lt $DesiredFileSizeKB
)
<##############################################################################
create transfer file
##############################################################################>
# copy the file to a shared and public internet location (I used my blog
# to host the file for example)
<##############################################################################
download file
##############################################################################>
# DownloadFile is the location of the public file
#
$DownloadFile = "http://your-file-location/transfer_file.txt"
$DestinationFile = "C:\temp\downloaded_file.txt"
$OutputFile = "C:\temp\network_test.csv"
$Iterations = 10
$WebClient = New-Object System.Net.WebClient
while ($true) {
$Output =
for ($i = 0; $i -lt $Iterations; $i++) {
$PreDownloadTimeStamp = Get-Date
$WebClient.DownloadFile($DownloadFile, $DestinationFile)
$PostDownloadTimeStamp = Get-Date
$TransferDurationSec = $PostDownloadTimeStamp.Subtract($PreDownloadTimeStamp).TotalSeconds
if (Test-Path $DestinationFile) {
$TransferSizeBytes = Get-ChildItem $DestinationFile | Select-Object -ExpandProperty Length
}
else {
$TransferSizeBytes = 0
}
$TransferSizeMb = $TransferSizeBytes / 1024 / 1024 * 8
$TransferThroughput = $TransferSizeMb / $TransferDurationSec
$i |
Select-Object @{Name = "CurrentDateTime"; Expression = { Get-Date }},
@{Name = "Iteration"; Expression = { $_ }},
@{Name = "Throughput"; Expression = { $TransferThroughput }}
}
$OutputAggregated =
$Output |
Measure-Object -Average Throughput |
Select-Object @{Name = "CurrentDateTime"; Expression = { Get-Date }},
@{Name = "ThroughputMbps"; Expression = { $_.Average }}
$OutputAggregated
$OutputAggregated | Export-Csv $OutputFile -NoTypeInformation -Append
Start-Sleep -Seconds 60
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment