Created
December 23, 2019 06:20
-
-
Save tejas-hosamani/91ed92acbb531cc8fcdb050e73d9d9ac to your computer and use it in GitHub Desktop.
Monitor mobile WiFi and reconnect, if not available | Windows | Powershell
This file contains hidden or 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
# 1) SSID of Wireless Network (CaSe Sensitive) | |
# netsh wlan show networks | |
$mySSID = 'Tejas' | |
# 2) Wireless Profile Name (CaSe Sensitive) | |
# netsh wlan show profile | |
$profileName = 'Tejas' | |
# 3) Name of Wireless Interface (CaSe Sensitive) | |
# netsh wlan show interfaces | |
$interfaceName = 'Wi-Fi' | |
$waitFor = 2 | |
$timeoutIn = 2 | |
$restartCount = 0 | |
For($a=1; ; $a++) { | |
Write-Host "Running $a st/nd/rd/th time(s).." | |
Write-Host "Reconnected $restartCount st/nd/rd/th time(s).." | |
ping -n 1 google.com > NULL | |
if (!$?) | |
{ | |
Write-Host "Restarting interface.." | |
netsh wlan disconnect interface="$interfaceName" | |
TIMEOUT $timeoutIn | |
netsh wlan connect ssid="$mySSID" Name="$profileName" Interface="$interfaceName" | |
TIMEOUT $timeoutIn | |
$restartCount++ | |
} | |
Write-Host sleeping $waitFor sec | |
sleep $waitFor | |
cls | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit: http://www.jeremyharlow.net/automatic-wi-fi-connectivity-checker-reconnect-script/
Original post was about making .bat file. I've made it for powerShell.
How to use:
$mySSID
,$profileName
and$interfaceName
) respectively at line number 3, 7 and 11 inside script. And save the file.C:\> /path/to/file/<file_name>.ps1
That's it.
If you open powerShell inside the same directory as that of this file:
C:\> ./<file_name>.ps1
Example:
./pingNow.ps1
Hope it's useful 🙂