Manage Windows Wi-Fi Profiles with Python and netsh

A Windows utility written in Python that uses netsh wlan to list saved Wi-Fi networks with their stored passwords and bulk-delete Wi-Fi profiles while keeping one network.

Python projects · Windows networking

⚠️ Running the script as it is deletes your saved Wi-Fi profiles. Both parts run one after the other: after listing the passwords, the script deletes every saved profile except the one named in ignore_ssid, which is set to the placeholder "WIFI_NAME". Unless you change ignore_ssid to your network’s name, or comment out the delete section, all saved Wi-Fi profiles are deleted.

Start here

Before running: this script prints saved Wi-Fi passwords and deletes saved profiles except the configured SSID. Read the deletion warning and edit the script first.

Read the requirements and any configuration below, then follow the usage example. Source paths below are relative to the repository root; run commands from the working directory stated in Usage. This example’s source is in Wifi Profiles/Console_Code/. Install any third-party packages in an isolated Python environment.

Overview

This script uses netsh wlan commands via subprocess to:

  1. Display all saved Wi-Fi SSIDs and their stored passwords
  2. Delete all saved Wi-Fi profiles except for one specified network

Both operations are in the same script and both run every time. To only list passwords, comment out the delete section (everything from the ignore_ssid line onwards).

Features

  • Lists all saved Wi-Fi profiles with their SSIDs and passwords
  • Bulk-deletes all Wi-Fi profiles except a designated “safe” SSID
  • Uses only Python standard library modules (subprocess, re)
  • No external dependencies

Prerequisites and installation

No external dependencies. Uses only Python standard library.

Windows only. Requires a Windows system with the WLAN AutoConfig service running.

Usage

Run from the Wifi Profiles/Console_Code/ directory, after reviewing and editing the deletion section:

python profile.py

Part 1 — List All SSIDs and Passwords

Runs first and prints output like:

SSID: HomeNetwork
Password: mypassword123
------------------------------
SSID: OfficeWifi
Password: No password
------------------------------

Part 2 — Delete All Profiles Except One

Runs immediately after Part 1. Before running the script, open profile.py and set the SSID you want to keep (the default value is the placeholder "WIFI_NAME"):

ignore_ssid = "YourNetworkName"

The script then deletes all other saved profiles, printing Skipping profile: ... for the kept network and Deleted profile: ... for each deleted one.

How It Works

Listing passwords:

  • Runs netsh wlan show profiles to get all saved SSIDs
  • For each SSID, runs netsh wlan show profile <name> key=clear to retrieve the stored password
  • Extracts the password using a regex on Key Content

Deleting profiles:

  • Retrieves the same profile list
  • Runs netsh wlan delete profile name=<name> for each profile not matching ignore_ssid

Architecture

Wifi Profiles/
└── Console_Code/
    └── profile.py    # Main script

Troubleshooting and limitations

  • You may need to run this script as Administrator to read stored passwords on some Windows configurations.
  • This tool is intended for personal use to manage your own saved Wi-Fi connections. Always use responsibly and with respect for privacy.
  • The script has no undo. Re-create profiles manually or restore a separately retained export. To keep a backup first, run netsh wlan export profile key=clear folder=<path> (the exported files contain passwords in plain text, so store them securely).
  • The deletion subprocess does not check its return code; a printed Deleted profile message alone does not prove deletion succeeded.
  • The profile list is parsed with the English label All User Profile, so on Windows installations in other display languages the script may find no profiles.


Read all Python Projects and Code Examples guides online · Project overview · All developer projects