diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 1ba6744..468f37c 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -34,6 +34,9 @@ Set WAU to run at user logon. .PARAMETER UpdatesInterval Specify the update frequency: Daily (Default), Weekly, Biweekly or Monthly. +.PARAMETER RunOnMetered +Run WAU on metered connection. Default No. + .EXAMPLE .\winget-install-and-update.ps1 -Silent -DoNotUpdate @@ -251,6 +254,9 @@ function Install-WingetAutoUpdate { if ($UseWhiteList) { New-ItemProperty $regPath -Name WAU_UseWhiteList -Value 1 -PropertyType DWord -Force | Out-Null } + if (!$RunOnMetered) { + New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value 1 -PropertyType DWord -Force | Out-Null + } Write-host "WAU Installation succeeded!" -ForegroundColor Green Start-sleep 1 diff --git a/Winget-AutoUpdate/functions/Test-Network.ps1 b/Winget-AutoUpdate/functions/Test-Network.ps1 index 9e5c332..0e331e5 100644 --- a/Winget-AutoUpdate/functions/Test-Network.ps1 +++ b/Winget-AutoUpdate/functions/Test-Network.ps1 @@ -14,7 +14,34 @@ function Test-Network { if ($TestNetwork) { Write-Log "Connected !" "Green" - return $true + + #Check for metered connection + [void][Windows.Networking.Connectivity.NetworkInformation, Windows, ContentType = WindowsRuntime] + $cost = [Windows.Networking.Connectivity.NetworkInformation]::GetInternetConnectionProfile().GetConnectionCost() + + if ($cost.ApproachingDataLimit -or $cost.OverDataLimit -or $cost.Roaming -or $cost.BackgroundDataUsageRestricted -or ($cost.NetworkCostType -ne "Unrestricted")){ + + 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 + + } + else{ + + Write-Log "WAU is configured to force update checking on metered connection" + return $true + + } + + } + else{ + + return $true + + } } else {