- Block or force upgrade to Windows 11 with Group Policy - Tue, Oct 26 2021
- Compress SMB data in Windows 11 and Server 2022 - Mon, Oct 4 2021
- Install Windows 11 in a virtual machine - Tue, Sep 28 2021
Windows 10 does include cmdlets for managing network profiles for LAN connections, but WiFi profiles cannot effectively be edited with Set-NetConnectionProfile. Instead, the notoriously cumbersome command line tool netsh.exe serves this purpose.
Similar to the management of NTFS permissions, a community module provides a remedy here, namely wifi¬profile¬management, by Microsoft employee Jason Walker. It covers all functions, including displaying the available networks, creating and changing profiles, and extracting passwords.
Installing WiFi-Module ^
The easiest way to install wifi¬profile¬management is via PowerShellGet:
Install-Module -Name wifiprofilemanagement
It may be necessary to update the NuGet provider and ignore the warning that PSGallery is not a trusted repository.
Create a new WLAN profile ^
When you set up a new connection, you usually start by displaying the available networks, just like when using the GUI. This is the purpose of the command
If necessary, you can pass the name of the WiFi adapter to the cmdlet via the WiFiAdapterName parameter. The available WLAN adapters can be found via
Get-NetAdapter -Physical | where PhysicalMediaType -eq "Native 802.11"
After you have decided which network you want to use, store the required password in a variable as a secure string:
$PW = Read-Host -AsSecureString
Now you can create a profile for this WLAN using its SSID as the name:
New-WiFiProfile -ProfileName MyWiFi -ConnectionMode manual ` -Authentication WPA2PSK -Password $PW -Encryption AES
For ConnectionMode, you can choose between manual and auto, which corresponds to selecting or deselecting the Connect automatically option in the GUI. The authentication method must, of course, be supported by the WLAN.
Show and export profiles, read password ^
With Get-WiFiProfile you can make sure that the profile has been created and check its properties.
This cmdlet also allows you to export the WiFi profile as an XML file (see Microsoft's examples for the exact format of the profiles). To do this, write the XML property to a file:
(Get-WiFiProfile -ProfileName MyWiFi).XML | Out-File .\MyWiFi.xml -Encoding utf8
In this example, the profile will be exported without the password. You can output it by adding the ClearKey switch:
Get-WiFiProfile -ProfileName MyWiFi -ClearKey | select Password
So for a complete XML export, you also must add this parameter. Note that only the user who created the profile will see the decrypted password.
The exported profile could be transferred to other computers and imported there with New-WiFiProfile. The cmdlet supports the XmlProfile parameter for this purpose. For this, you first load the XML file into a variable, not as an XML structure, but as plain text:
$profile = gc -Raw .\MyWiFi.xml
Then run the command like this:
New-WiFiProfile -XmlProfile $profile
Connect to WLAN ^
Once the required profile is created, you can use it to connect to the corresponding network. This is done by calling the cmdlet
Connect-WiFiProfile -ProfileName MyWiFi
As optional parameters, it accepts the AdapterName, which can be determined as described above, as well as ConnectionMode to override the setting from the profile.
The module does not provide a cmdlet to disconnect a WLAN connection, so you have to use netsh for that:
netsh wlan disconnect interface="Wi-Fi"
You can again get the interface via Get-NetAdapter.
Changing or deleting profiles ^
Existing WiFi profiles can be modified with Set-WiFiProfile. It supports the same parameters as New-WiFiProfile, so you can change any setting that you configured with it when you first created it.
For example, if you want to renew the password, proceed as follows:
Set-WiFiProfile -ProfileName MyWiFi -Password $NewPW
Similarly, you can set a new mode for authentication or encryption.
Alternatively, you can completely overwrite the existing settings with a different version of the WiFi profile if this is available in XML format. Here, too, the XmlProfile parameter does the job; it is called in the same way as New-WiFiProfile.
Subscribe to 4sysops newsletter!
If you no longer need a network profile, you can remove it with Remove-WiFiProfile. The cmdlet receives the name of the profile via the ProfileName parameter. Optionally, you can also specify the adapter via WiFiAdapterName.