2022-04-13 16:50:06 +00:00
|
|
|
#Function to check connectivity
|
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
function Test-Network {
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-03-22 13:39:01 +00:00
|
|
|
#Init
|
2022-03-14 13:55:02 +00:00
|
|
|
$timeout = 0
|
|
|
|
|
2022-03-22 13:39:01 +00:00
|
|
|
#Test connectivity during 30 min then timeout
|
2022-03-14 13:55:02 +00:00
|
|
|
Write-Log "Checking internet connection..." "Yellow"
|
2022-06-10 08:26:41 +00:00
|
|
|
While ($timeout -lt 1800) {
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-03-22 13:39:01 +00:00
|
|
|
$TestNetwork = Test-NetConnection 8.8.8.8 -Port 443 -InformationLevel Quiet
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-06-10 08:26:41 +00:00
|
|
|
if ($TestNetwork) {
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
Write-Log "Connected !" "Green"
|
2022-06-29 15:32:03 +00:00
|
|
|
|
|
|
|
#Check for metered connection
|
|
|
|
[void][Windows.Networking.Connectivity.NetworkInformation, Windows, ContentType = WindowsRuntime]
|
|
|
|
$cost = [Windows.Networking.Connectivity.NetworkInformation]::GetInternetConnectionProfile().GetConnectionCost()
|
|
|
|
|
2022-10-18 13:23:39 +00:00
|
|
|
if ($cost.ApproachingDataLimit -or $cost.OverDataLimit -or $cost.Roaming -or $cost.BackgroundDataUsageRestricted -or ($cost.NetworkCostType -ne "Unrestricted")) {
|
2022-06-29 15:32:03 +00:00
|
|
|
|
|
|
|
Write-Log "Metered connection detected." "Yellow"
|
|
|
|
|
|
|
|
if ($WAUConfig.WAU_DoNotRunOnMetered -eq 1) {
|
|
|
|
|
|
|
|
Write-Log "WAU is configured to bypass update checking on metered connection"
|
|
|
|
return $false
|
|
|
|
|
|
|
|
}
|
2022-10-18 13:23:39 +00:00
|
|
|
else {
|
2022-06-29 15:32:03 +00:00
|
|
|
|
|
|
|
Write-Log "WAU is configured to force update checking on metered connection"
|
|
|
|
return $true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-10-18 13:23:39 +00:00
|
|
|
else {
|
2022-06-29 15:32:03 +00:00
|
|
|
|
|
|
|
return $true
|
|
|
|
|
|
|
|
}
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
}
|
2022-06-10 08:26:41 +00:00
|
|
|
else {
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
Start-Sleep 10
|
|
|
|
$timeout += 10
|
2022-03-22 13:39:01 +00:00
|
|
|
|
|
|
|
#Send Warning Notif if no connection for 5 min
|
2022-06-10 08:26:41 +00:00
|
|
|
if ($timeout -eq 300) {
|
2022-03-14 13:55:02 +00:00
|
|
|
Write-Log "Notify 'No connection' sent." "Yellow"
|
|
|
|
$Title = $NotifLocale.local.outputs.output[0].title
|
|
|
|
$Message = $NotifLocale.local.outputs.output[0].message
|
|
|
|
$MessageType = "warning"
|
|
|
|
$Balise = "connection"
|
|
|
|
Start-NotifTask $Title $Message $MessageType $Balise
|
|
|
|
}
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
}
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
}
|
2022-03-22 13:39:01 +00:00
|
|
|
|
|
|
|
#Send Timeout Notif if no connection for 30 min
|
2022-03-14 13:55:02 +00:00
|
|
|
Write-Log "Timeout. No internet connection !" "Red"
|
|
|
|
$Title = $NotifLocale.local.outputs.output[1].title
|
|
|
|
$Message = $NotifLocale.local.outputs.output[1].message
|
|
|
|
$MessageType = "error"
|
|
|
|
$Balise = "connection"
|
|
|
|
Start-NotifTask $Title $Message $MessageType $Balise
|
|
|
|
return $false
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
}
|