I want to write a Powershell script that acts as a toggle for a connection to the internet each time it is run. I wrote this, which works:
$isconnected = netsh wlan show interfaces | select-string SSID | Out-String
if($isconnected.length -eq 0)
{
netsh wlan connect "My Network Name"
}
else
{
netsh wlan disconnect
}
but I'm not sure if there are situations where this might fail. One that comes to mind is whenever the computer is on a new network whose name isn't specified in the script. Is there some way to get around specifying the network name? Are there better ways to do this?