Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add wifi profile with password in windows programmatically

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

like image 633
cSteusloff Avatar asked Feb 05 '16 19:02

cSteusloff


1 Answers

I wrote a power shell script - the first three lines in the following code havent been tested as in my script I get it from a CSV file - the rest is as is - and works on the two SSIds I have

$profilefile="ACprofile.xml"
$SSID="ACSSID"
$PW="12345678"

$SSIDHEX=($SSID.ToCharArray() |foreach-object {'{0:X}' -f ([int]$_)}) -join''
$xmlfile="<?xml version=""1.0""?>
<WLANProfile xmlns=""http://www.microsoft.com/networking/WLAN/profile/v1"">
    <name>$SSID</name>
    <SSIDConfig>
        <SSID>
            <hex>$SSIDHEX</hex>
            <name>$SSID</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>$PW</keyMaterial>
            </sharedKey>
        </security>
    </MSM>
</WLANProfile>
"

$XMLFILE > ($profilefile)
netsh wlan add profile filename="$($profilefile)"
netsh wlan show profiles $SSID key=clear
netsh wlan connect name=$SSID
like image 69
Ross Avatar answered Oct 17 '22 08:10

Ross