Search code examples
powershellwindows-10connectionwifi

Connecting to WiFi using Powershell NOT knowing the SSID


The Problem

Microsoft has rolled out a buggy update that has glitched all wifi-options in the control panel and removed the wifi from the taskbar on my girlfriend's Windows 10 computer. So I would like to be able to connect to the wifi using powershell. The closest I have found is this post, but it assumes a SSID and a Profile. So how do I connect to a wifi network from scratch using powershell?

What I have tried

1. Listing network adapters
Get-NetAdapter

I find one called "WiFi-2" with the status Up, so all must be good right?

2. Listing all available networks
netsh wlan show networks

It shows the same networks as I can list on my working computer. So the network adapter seems to work.

3. Listing profiles
netsh wlan show profile

Apparantly you need at profile to be able to connect via powershell. I can list the profiles for already known networks only, but there are none for new networks. I take the working computer and export a profile to XML.

netsh wlan export profile name="WIFI-NETWORK-NAME" folder=.

I transferred this XML via USB to the computer with the windows 10 bug, and then import it.

netsh wlan add filename=WIFI-NETWORK-NAME.xml

Now I use this post to connect to the network.

netsh wlan connect name="WIFI-NETWORK-NAME" ssid="WIFI-NETWORK-NAME" interface="WiFi"
>Connection request was completed successfully

Great news! Buuuuut.... I can still not access any sites through the browser or curl.

4. Diagnosing Connection
netsh wlan show wlanreport

An HTML report is generated, and it says that the connection could not be created.

I am a bit stuck here. How do I know if my wifi-connection is up or not? How do I connect to unknown networks via powershell (do I have to write XML manually?)? How do I know if my network card is working? I hope someone can help me out.


Solution

  • You also need to add key=clear if you want the password to export. Without it, you can only decrypt it on the same user/computer.

    netsh wlan export profile name="WIFI-NETWORK-NAME" folder=. key=clear
    

    If the exported profile is set to connect automatically, the wifi should just connect after you import it.

    netsh wlan add filename=WIFI-NETWORK-NAME.xml
    

    When trying to connect manually, I found you didn't need to specify the adapter or the ssid, just the profile name.

    netsh wlan connect name="WIFI-NETWORK-NAME"
    

    If you need to specify the interface, specify the correct interface name. You stated it was WiFi-2

    netsh wlan connect name="WIFI-NETWORK-NAME" ssid="WIFI-NETWORK-NAME" interface="WiFi-2"