Skip to content

Instantly share code, notes, and snippets.

@LikeCarter
Created May 21, 2025 12:58
Show Gist options
  • Select an option

  • Save LikeCarter/ca11acc5742d04f53563ed4229f9a156 to your computer and use it in GitHub Desktop.

Select an option

Save LikeCarter/ca11acc5742d04f53563ed4229f9a156 to your computer and use it in GitHub Desktop.
$interfaceName = "Wi-Fi"
# Check if the interface is up and connected
$interface = Get-NetAdapter -Name $interfaceName -Physical | Where-Object { $_.Status -eq "Up" }
if ($interface) {
# Check for internet connectivity using Test-NetConnection
$test = Test-NetConnection -ComputerName 8.8.8.8 -InformationLevel Quiet
if (-not $test) {
# Reset DNS servers if no connectivity
Set-DnsClientServerAddress -InterfaceAlias $interfaceName -ResetServerAddresses
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment