Add wifi profile with password in windows programmatically

cSteusloff picture cSteusloff · Feb 5, 2016 · Viewed 38.1k times · Source

Is it possible to programmatically add a wifi profile to a windows operating system (minimum version windows 7)?

I tried netsh with add profile and connect, but it doesn't work for me. Is there any powershell commands which does this?

I want to set a wifi password for a special ssid for many clients automatically.

I hope someone has an idea or can give me a command with this sample information:

  • SSID: WifiNetwork
  • Password: Password123

Thanks

Answer

cSteusloff picture cSteusloff · Feb 5, 2016

I found a way to add a wifi profile.

At first you export an existing wifi profile:

netsh wlan export profile name="WifiNetwork" folder="C:\path\" key=clear

Than you get a XML file with the following style:

<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
    <name>WifiNetwork</name>
    <SSIDConfig>
        <SSID>
            <hex>576966694E6574776F726B</hex>
            <name>WifiNetwork</name>
        </SSID>
    </SSIDConfig>
    <connectionType>ESS</connectionType>
    <connectionMode>auto</connectionMode>
    <MSM>
        <security>
            <authEncryption>
                <authentication>WPA2PSK</authentication>
                <encryption>AES</encryption>
                <useOneX>false</useOneX>
            </authEncryption>
            <sharedKey>
                <keyType>passPhrase</keyType>
                <protected>false</protected>
                <keyMaterial>Password123</keyMaterial>
            </sharedKey>
        </security>
    </MSM>
</WLANProfile>

Than you can modify this file and import it to add this wifi with this command:

netsh wlan add profile filename="C:\path\WifiNetwork.xml"

Check your profiles with:

netsh wlan show profile

Check your profile with key:

netsh wlan show profiles WifiNetwork key=clear

I hope I could help someone with this information.