Forked from trstringer/LoopingNetworkSpeedTest.ps1
Last active
August 29, 2015 14:24
-
-
Save TheRockStarDBA/43a5e9e3985e54ddbc3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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