Featured image of post Automating with PowerShell: Deploying WiFi Profiles

Automating with PowerShell: Deploying WiFi Profiles

I’m working with one of my collaborators to create scripts for their RMM system and they got a request from one of their clients “Can we add WiFi profiles using PowerShell?” and of course I pointed them to my blog. Only to find to my shame that I never blogged about it.

Adding WiFi profiles is very straight forward when you’re using a domain environment, you simply create a GPO and click around in the settings until you’ve perfected your setup, but in modern styled environments it’s not always that easy, and of course you want to use your RMM system to deploy the correct Wi-Fi Settings to all users.

So, let’s jump into that; today we’re adding a Wifi Connecting that uses a WPA2 PSK with AES encryption – The most commonly used network these days.

The Script

You’ll have to set $SSID and $PSK to your prefered SSID and PSK, remember that the SSID is case sensitive too.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
param(
    [string]$SSID,
    [string]$PSK
)
$guid = New-Guid
$HexArray = $ssid.ToCharArray() | foreach-object { [System.String]::Format("{0:X}", [System.Convert]::ToUInt32($_)) }
$HexSSID = $HexArray -join ""
@"
<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
	<name>$($SSID)</name>
	<SSIDConfig>
		<SSID>
			<hex>$($HexSSID)</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>$($PSK)</keyMaterial>
			</sharedKey>
		</security>
	</MSM>
	<MacRandomization xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">
		<enableRandomization>false</enableRandomization>
		<randomizationSeed>1451755948</randomizationSeed>
	</MacRandomization>
</WLANProfile>
"@ | out-file "$($ENV:TEMP)\$guid.SSID"

netsh wlan add profile filename="$($ENV:TEMP)\$guid.SSID" user=all

remove-item "$($ENV:TEMP)\$guid.SSID" -Force

And that’s it! using this script you can deploy Wi-Fi to your clients with relative ease 🙂 As always, Happy PowerShelling.

All blogs are posted under AGPL3.0 unless stated otherwise
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy