Search notes:

wlan-reconnect.ps1

wlan-reconnect.ps is a PowerShell script that uses the cmdlet text-connection to regularly check the WLAN connection and tries to reconnect with netsh wlan if it is gone.
This script was somewhat useful when I had to work in a room with a shaky WLAN.
If executed without parameter, it tries to connect to the SID named oooOOOooo. If executed with a parameter, the parameter is expected to be the name of the SID that the scripts should connect to:
wlan-reconnect OfficeX
The -speak flag can be specifed so that the script uses the Microsoft Speech Object Library to notify a change in the connection status:
wlan-reconnect OfficeX -speak

Script

param (
  [string] $ssid  = 'oooOOOooo',
  [switch] $speak
)

set-strictMode -version latest

#if ($args.count -lt 1) {
#  $ssid = 'oooOOOooo'
#}
#else {
#  $ssid = $args[0]
#}

if ($speak) {
   $sapi = new-object -comObject sapi.spVoice
   $lastStatus = '?'
}

$host.ui.rawUi.windowTitle = "wlan reconnect $ssid"


while ($true) {
   $now = get-date -format 'HH:mm:ss'

   if (! (test-connection 8.8.8.8 -errorAction continue -count 1 -quiet) ) {
     "$now NOK"
      $null = netsh wlan connect $ssid

      if ($speak -and $lastStatus -ne 'NOK') {
         $null = $sapi.speak('connection down')
         $lastStatus = 'NOK'
      }
      start-sleep 1
   }
   else {
     "$now OK"

      if ($speak -and $lastStatus -ne 'OK') {
         $null = $sapi.speak('connection up')
         $lastStatus = 'OK'
      }
      start-sleep 15
   }

}
Github repository scripts-and-utilities, path: /wlan-reconnect.ps1

See also

Other Scripts

Index