I only want to run my restic backups on non-metered networks.
Given this, I want to kill my backup process if I connect to a metered network, and start it (if necessary) on connection to a non-metered network.
Note: I want to allow my backup to resume if possible, so killing it on disconnection is not an option.
I can run a task on connection to a network, but I don't know how a task (my batch file) can determine if my network is metered.
How do I find the metered / unmetered status of the current network from the command line?
This snippet by nijave does what you want:
[void][Windows.Networking.Connectivity.NetworkInformation, Windows, ContentType = WindowsRuntime]
$cost = [Windows.Networking.Connectivity.NetworkInformation]::GetInternetConnectionProfile().GetConnectionCost()
$cost.ApproachingDataLimit -or $cost.OverDataLimit -or $cost.Roaming -or $cost.BackgroundDataUsageRestricted -or ($cost.NetworkCostType -ne "Unrestricted")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With