winutil/functions/private/Test-WinUtilInternetConnection.ps1
CodingWonders 674d1368bb
[Offline] Fixed invalid command in PWSH 5 (#3604)
-TimeoutSeconds is not a parameter in Test-Connection for PWSH 5
2025-09-21 16:21:18 -05:00

27 lines
684 B
PowerShell

function Test-WinUtilInternetConnection {
<#
.SYNOPSIS
Tests if the computer has internet connectivity
.OUTPUTS
Boolean - True if connected, False if offline
#>
try {
# Test multiple reliable endpoints
$testSites = @(
"8.8.8.8", # Google DNS
"1.1.1.1", # Cloudflare DNS
"208.67.222.222" # OpenDNS
)
foreach ($site in $testSites) {
if (Test-Connection -ComputerName $site -Count 1 -Quiet -ErrorAction SilentlyContinue) {
return $true
}
}
return $false
}
catch {
return $false
}
}