Closed pawanadubey closed 1 year ago
Great idea-some thoughts.
Invoke-WebRequest
? Personally, I kind of like using Start-BitsTransfer
as it's simpler to explain and uses a few less lines of code to do the gransfer.Here is a simple suggestion - comments?
# 1. Defining the file to be tested
$FILE = 'https://archive.org/download/gd74-07-21.' +
'fob-patched.miller.31436.sbeok.flacf/gd74-07-21d1t01.flac'
$DEST = 'C:\Foo\TPL.Flac'
"Testing a download of [$FILE]"
"Storing at [$DEST]"
# 2. Timing the download
$Start = Get-Date
Start-BitsTransfer -Source $FILE -Destination c:\foo\TPL.FLAC
$End = Get-Date
# 3. Calculating the time taken
$TimeTaken = $End-$Start
# 4. Displaying time taken
$Seconds = $TimeTaken.TotalSeconds
"Total seconds taken to perform download [$($TimeTaken.TotalSeconds)"
# 5. Calculate bytes/sec
$Size = (Get-ChildItem -Path $DEST).Length
$Speed = ($Size/$Seconds).ToString('N2')
# 6. Display the speed achieved
"Download speed (bytes/second) [$Speed]"
@doctordns Your code snippet is a good starting point. 👍
I took it and tried to use the desired Invoke-WebRequest instead of Start-BitsTransfer, as I'm more familiar with Invoke-WebRequest.
Actually, Invoke-WebRequest is not that difficult to explain. It works when URI and Outfile are specified.
# 1. Defining the file to be tested
$FILE = 'https://archive.org/download/gd74-07-21.' +
'fob-patched.miller.31436.sbeok.flacf/gd74-07-21d1t01.flac'
$DEST = 'C:\Foo\TPL.Flac'
"Testing a download of [$FILE]"
"Storing at [$DEST]"
# 2. Timing the download
$Start = Get-Date
Invoke-WebRequest -Uri $FILE -OutFile $DEST
$End = Get-Date
# 3. Calculating the time taken
$TimeTaken = $End-$Start
# 4. Displaying time taken
$Seconds = $TimeTaken.TotalSeconds
"Total seconds taken to perform download [$($TimeTaken.TotalSeconds)]"
# 5. Calculate bytes/sec
$Size = (Get-ChildItem -Path $DEST).Length
$Speed = ($Size/$Seconds).ToString('N2')
# 6. Display the speed achieved
"Download speed (bytes/second) [$Speed]"
I think it's a matter of choice.
Another point: The user should be informed that the output directory ("C:\foo" in this case) is not automatically created if it doesn't exist. The error message from PowerShell could be a little bit misleading. 🤔
Mayabe the post should cover both methods and see if there is a time difference? BITS works in the background, and IIRC, Invoke-WebRequest works in the foreground so the latter would probably show a faster speed. Might be useful to show both and explain.
@termdew Are you still interested in writing this post?
Check download speed of connected internet
Many times we are needed to run a speed test on machines to verify that machines have the acceptable speed to use certain applications effectively.
The goal is to
PowerShell command to explain: Invoke-WebRequest