diff --git a/Winget-AutoUpdate/functions/Test-Network.ps1 b/Winget-AutoUpdate/functions/Test-Network.ps1 index 2284b20..10e3dc1 100644 --- a/Winget-AutoUpdate/functions/Test-Network.ps1 +++ b/Winget-AutoUpdate/functions/Test-Network.ps1 @@ -17,11 +17,15 @@ function Test-Network { $ncsiHost = "www.msftconnecttest.com" $ncsiPath = "connecttest.txt" $ncsiContent = "Microsoft Connect Test" - } finally { - $ncsiResponse = Invoke-WebRequest -Uri "http://$($ncsiHost)/$($ncsiPath)" -UseBasicParsing } - if (($ncsiResponse.StatusCode -eq 200) -and ($ncsiResponse.content -eq $ncsiContent)) { + try { + $ncsiResponse = Invoke-WebRequest -Uri "http://$($ncsiHost)/$($ncsiPath)" -UseBasicParsing + } catch { + $ncsiResponse = $false + } + + if (($ncsiResponse) -and ($ncsiResponse.StatusCode -eq 200) -and ($ncsiResponse.content -eq $ncsiContent)) { Write-ToLog "Connected !" "Green" #Check for metered connection