-
-
Save p0w3rsh3ll/2e2da2091e3669cc89803b74c0d7aea7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Test-isUsingMeteredConnection { | |
<# | |
.SYNOPSIS | |
Test if a metered connection is in use | |
.DESCRIPTION | |
Test if a metered connection is in use | |
.EXAMPLE | |
Test-isUsingMeteredConnection | |
False | |
#> | |
[OutputType([System.Boolean])] | |
[CmdletBinding()] | |
Param() | |
Begin { | |
try { | |
$null = [Windows.Networking.Connectivity.NetworkInformation, Windows, ContentType = WindowsRuntime] | |
$connectionProfile = [Windows.Networking.Connectivity.NetworkInformation]::GetInternetConnectionProfile() | |
} catch { | |
Throw $_ | |
} | |
} | |
Process {} | |
End { | |
if ($connectionProfile) { | |
$cost = $connectionProfile.GetConnectionCost() | |
if ($cost.ApproachingDataLimit -or $cost.OverDataLimit -or | |
$cost.Roaming -or $cost.BackgroundDataUsageRestricted -or | |
( | |
($cost.NetworkCostType -ne [Windows.Networking.Connectivity.NetworkCostType]::Unrestricted.value__) -and | |
($cost.NetworkCostType -ne [Windows.Networking.Connectivity.NetworkCostType]::Unknown.value__) | |
) | |
) { | |
return $true | |
} else { | |
return $false | |
} | |
} else { | |
$false | |
} | |
} | |
} | |
Export-ModuleMember -Function 'Test-isUsingMeteredConnection' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment