Skip to content

Instantly share code, notes, and snippets.

@mavaddat
Last active October 5, 2021 02:25
Show Gist options
  • Save mavaddat/30e1c0cb20f6a1800e3ed7f728a69763 to your computer and use it in GitHub Desktop.
Save mavaddat/30e1c0cb20f6a1800e3ed7f728a69763 to your computer and use it in GitHub Desktop.
This script removes the needless enumeration on the end of WiFi names (e.g., "Network 2", "Network 3", "Network 4", etc.) that sometimes happens in Windows when the computer does not recognize an SSID that it has connected to previously. It also logs the changes it makes in the Windows event log.
#Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; Invoke-Expression $($(Invoke-RestMethod -Method Get -Uri 'https://api.github.com/gists/30e1c0cb20f6a1800e3ed7f728a69763').files.'removeNumerationFromWifiNames.ps1'.content)
if (-not $(New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
$Host.UI.WriteErrorLine("You need to be running PowerShell as an administrator to run this script. Please open an admin PowerShell session and try again.")
exit
}
$scriptName = 'removeNumerationFromWifiNames.ps1'
try {
if (Get-Command -Name Get-EventLog -CommandType Function -ErrorAction Ignore) {
Get-EventLog -LogName Application -Source $scriptName -ErrorAction Ignore
}
}
catch [GetEventLogNoEntriesFound] {
New-EventLog -Source $scriptName -LogName Application
}
Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\' | ForEach-Object {
if ($_.Property -contains 'ProfileName' -and $_.Property -contains 'Description' -and $_.GetValue('ProfileName') -match "$($_.GetValue('Description'))\s+\d+") {
Write-EventLog -LogName Application -Source $scriptName -EntryType SuccessAudit -EventId $(if (Get-Variable -Name PID -Scope Global `
-ErrorAction SilentlyContinue) { $PID } else { (Get-Process -Name 'PowerShell').Id }) `
-Message "Successfully changed wifi profile name from $($_.GetValue('ProfileName')) to $($_.GetValue('Description'))"
Set-ItemProperty -Path "HKLM:$_" -Name 'ProfileName' -Value $($_.GetValue('Description'))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment