Batch file looking for Wi-Fi connection – reconnects when no Internet is available

There is a remote Windows PC that has access to "landline Wi-Fi" and there is a Verizon 4G LTE-Mifi (measured Wi-Fi) as a backup. This script checks to see if the PC is connected to a Wi-Fi network, connected to a measured Wi-Fi network, or has an Internet connection. It is called by the Task Scheduler several times a day. When testing at home everything seems to be fine. Feedback is appreciated

@echo off
SETLOCAL enabled delayed extension

rem gets the SSID of the connected WLAN
for / f "eol = # tokens = 2delims =:" %% a IN (& netsh wlan show interface ^ | find "SSID:" & # 39;) SET SET wifi = %% a

current WLAN is% WLAN%

if "% wifi%" == "" (
Echo No Wi-Fi detected. Connection to the WLAN.
netsh wlan connect name = "Unmetered Wifi"
Timeout / t 10
rem gets the SSID of the connected WLAN
for / f "eol = # tokens = 2delims =:" %% a IN (& netsh wlan show interface ^ | find "SSID:" & # 39;) SET SET wifi = %% a
Echo Now associated with% wifi%
) otherwise (Echo Wifi connected)

rem If connected to a measured WLAN (contains "Verizon"), switch to WLAN
if not "% wifi%" == "% wifi: verizon =%" (
Echo measured Wi-Fi detected. Connection to the WLAN.
netsh wlan connect name = "Unmetered Wifi"
Timeout / t 10
) else (Echo Wifi connected to landline)


rem If the connection to the WLAN has not been established, access the WLAN
ping 8.8.8.8 -n 1> nul || netsh wlan connect name = "Verizon-4GLTE-xxxx"