Skip to content

Instantly share code, notes, and snippets.

@HighLibrarian
Created September 11, 2025 11:55
Show Gist options
  • Select an option

  • Save HighLibrarian/c868c1d5c4074f9ced0581849dd76262 to your computer and use it in GitHub Desktop.

Select an option

Save HighLibrarian/c868c1d5c4074f9ced0581849dd76262 to your computer and use it in GitHub Desktop.
Powershell Wifi profile configuration
<#
.SYNOPSIS
Creates and installs a new Wi-Fi (WLAN) profile using a specified SSID and pre-shared key.
.DESCRIPTION
This script automates the creation of a wireless network profile on a Windows system.
It takes a Wi-Fi SSID and pre-shared key (PSK) as input, converts the SSID to its hexadecimal form,
generates a WLAN profile XML configuration, and adds it to the system using 'netsh wlan add profile'.
After installation, the temporary XML file is deleted. This is useful for quickly deploying Wi-Fi settings
across multiple machines without manual user input.
.PARAMETER WlanSSID
The name (SSID) of the Wi-Fi network to create and install as a profile.
.PARAMETER PreSharedKey
The pre-shared key (WPA2 passphrase) to use when connecting to the Wi-Fi network.
.NOTES
This script requires administrative privileges and is only supported on Windows systems
with the 'netsh' utility available.
.LINK
https://gist.github.com/HighLibrarian/c868c1d5c4074f9ced0581849dd76262
.EXAMPLE
.\Add-WifiProfile.ps1 -WlanSSID "MyNetwork" -PreSharedKey "MySecurePassword"
Creates and installs a WLAN profile named 'MyNetwork' with the specified password.
.AUTHOR
HighLibrarian
.VERSION
202509
#>
param
(
[string]$WlanSSID,
[string]$PreSharedKey
)
# Create a timestamp instead of a GUID
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
# Convert SSID to hexadecimal
$HexArray = $WlanSSID.ToCharArray() | ForEach-Object {
[System.String]::Format("{0:X}", [System.Convert]::ToUInt32($_))
}
$HexSSID = $HexArray -join ""
# Build the WLAN profile XML
@"
<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>$($WlanSSID)</name>
<SSIDConfig>
<SSID>
<hex>$($HexSSID)</hex>
<name>$($WlanSSID)</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>$($PreSharedKey)</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)\$timestamp.SSID"
# Add the WLAN profile
netsh wlan add profile filename="$($ENV:TEMP)\$timestamp.SSID" user=all
# Clean up temporary file
Remove-Item "$($ENV:TEMP)\$timestamp.SSID" -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment