Deleting from Reg based on Search

Topics: Archive - General
Jul 14, 2014 at 9:04 PM
Edited Jul 14, 2014 at 9:05 PM
We’re currently upgrading to a new Wireless system and with that we’re pushing out the SSID through a GPO. However, we would like to remove the existing SSID/Profile from the system, which isn’t an issue with simply using “netsh wlan delete profile name”. The problem we’re having is removing these profiles from our user’s “Lenovo Access Connections” which is managing most (if not all) user’s various network profiles. If it’s deleted with the netsh, the user can simply open up Access Connections and it will recreate that profile within Windows.
We cannot simply delete the profiles since each user can name our company network with whatever nickname they want within the program. That being said, I’ve found where these profiles are stored within the registry.

Lenovo Access Connections
HKLM\SOFTWARE\Wow6432Node\Lenovo\Access Connections\Locations

This is where the problem lies, I cannot figure a means to search within the \Locations folder for our SSID, then delete it’s main key. It is currently laid out like this:
\Locations\(Custom Profile Name)\AdptList\Adpt00\
Within the Adpt00 Key there is a Reg_SZ with the name of m_szSsid with it’s value = Our Network’s SSID. So, basically I’m looking to search ALL of \Locations and if any of the m_szSsid within the Adpt00 Key for each of the varying Profiles exists… delete the entire Profile from \Locations, and yes some of our user’s have multiple Profile’s setup for the same Network SSID for a reason unknown to me. Is this even a possibility?
Jul 15, 2014 at 8:47 PM
Yes, it sounds possible. You would need to enumerate all the profiles under the Locations key in a foreach loop, getting the PSPath of each of those Custom Profile keys and drilling down in to the Adpt00 key to look for the m_szSsid.
Jul 16, 2014 at 6:20 PM
Thanks PS,

I think I am heading in the right direction now, here is what I have come up with so far, but I've hit a block with my limited knowledge and I'm scouring resources for next step.
$LACKey = "HKLM:\SOFTWARE\Wow6432Node\Lenovo\Access Connections\Locations"
$LACProfileKey = Get-ChildItem $LACKey -Recurse -ErrorAction SilentlyContinue | ForEach-Object {
   If((Get-ItemProperty -Path $_.PsPath) -match "m_szSsid")
This returns the only profile under \Locations for the current test machine (which only contains one matching profile), but from here I'm unsure of how to delete the Profile folder once found.