Skip to content

Commit 03027f9

Browse files
committed
fix: make downloads compatible with PS 5.1/7+
- PS1: conditional Invoke-WebRequest params (UseBasicParsing/TimeoutSec) - BAT: robust download script using param detection for Invoke-WebRequest
1 parent 4095a0b commit 03027f9

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

SystemTester.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ if /i not "%confirm%"=="Y" goto MENU
274274

275275
echo.
276276
echo Downloading...
277-
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ProgressPreference='SilentlyContinue'; try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%DOWNLOAD_URL%' -OutFile '%ZIP_FILE%' -TimeoutSec %DOWNLOAD_TIMEOUT_SEC%; Write-Host 'Download complete' -ForegroundColor Green } catch { Write-Host ('ERROR: ' + $_.Exception.Message) -ForegroundColor Red; exit 1 }"
277+
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ProgressPreference='SilentlyContinue'; try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $iwc = Get-Command Invoke-WebRequest -ErrorAction SilentlyContinue; $p = @{ Uri = '%DOWNLOAD_URL%'; OutFile = '%ZIP_FILE%' }; if ($iwc -and $iwc.Parameters.ContainsKey('UseBasicParsing')) { $p.UseBasicParsing = $true }; if ($iwc -and $iwc.Parameters.ContainsKey('TimeoutSec')) { $p.TimeoutSec = %DOWNLOAD_TIMEOUT_SEC% }; Invoke-WebRequest @p; Write-Host 'Download complete' -ForegroundColor Green } catch { Write-Host ('ERROR: ' + $_.Exception.Message) -ForegroundColor Red; exit 1 }"
278278

279279
if errorlevel 1 (
280280
echo.

SystemTester.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,12 @@ function Test-NetworkSpeed {
537537
$tempFile = [System.IO.Path]::GetTempFileName()
538538
Write-Host "Running internet download test (~10MB)..." -ForegroundColor Yellow
539539
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
540-
Invoke-WebRequest -Uri $testUrl -OutFile $tempFile -UseBasicParsing -TimeoutSec 120 | Out-Null
540+
# Use compatible parameters across PowerShell versions
541+
$iwc = Get-Command Invoke-WebRequest -ErrorAction SilentlyContinue
542+
$iwParams = @{ Uri = $testUrl; OutFile = $tempFile }
543+
if ($iwc -and $iwc.Parameters.ContainsKey('UseBasicParsing')) { $iwParams.UseBasicParsing = $true }
544+
if ($iwc -and $iwc.Parameters.ContainsKey('TimeoutSec')) { $iwParams.TimeoutSec = 120 }
545+
Invoke-WebRequest @iwParams | Out-Null
541546
$stopwatch.Stop()
542547

543548
$fileInfo = Get-Item $tempFile

0 commit comments

Comments
 (0)