Created
June 9, 2025 12:12
-
-
Save conkonig/24b31d2bcbe3c1ff5f6fac85bf1f1496 to your computer and use it in GitHub Desktop.
Windows Bluetooth Device Force Removal Tool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Bluetooth Device Removal Tool | |
| Get-PnpDevice -Class Bluetooth | |
| function Prompt-Choice { | |
| param ($Message, $Choices) | |
| $choice = $null | |
| while (-not $Choices -contains $choice) { | |
| $choice = Read-Host "$Message [$($Choices -join '/')]" | |
| } | |
| return $choice | |
| } | |
| Write-Host "Bluetooth Device Removal Tool" -ForegroundColor Cyan | |
| $keyword = Read-Host "Enter device search keyword (e.g., Xbox, JBL)" | |
| if ([string]::IsNullOrWhiteSpace($keyword)) { $keyword = "Xbox" } | |
| $keyword = "*$keyword*" | |
| # Scan for matching devices | |
| $devices = Get-PnpDevice -Class Bluetooth | Where-Object { $_.FriendlyName -like $keyword } | |
| if (!$devices) { | |
| Write-Host "No devices found matching '$keyword'." -ForegroundColor Yellow | |
| exit | |
| } | |
| # Display found devices | |
| Write-Host "`nFound $($devices.Count) device(s):" | |
| $i = 0 | |
| $devices | ForEach-Object { | |
| Write-Host "$i. $($_.FriendlyName) - $($_.InstanceId)" | |
| $i++ | |
| } | |
| # Ensure we wait for the user's choice | |
| $selectedDevices = @() | |
| $choice = "" | |
| while ($choice -notin @("all", "select", "exit")) { | |
| $choice = Read-Host "`nDo you want to remove all, select specific devices, or exit? [all/select/exit]" | |
| } | |
| # Replace switch with simple if to ensure global scope works | |
| if ($choice -eq "all") { | |
| $selectedDevices = $devices | |
| } | |
| elseif ($choice -eq "select") { | |
| $indexes = Read-Host "Enter comma-separated indexes to remove (e.g. 0,2,3)" | |
| $indexes = $indexes -split "," | ForEach-Object { $_.Trim() } | Where-Object { $_ -match '^\d+$' } | |
| foreach ($index in $indexes) { | |
| if ($index -lt $devices.Count) { | |
| $selectedDevices += $devices[$index] | |
| } | |
| } | |
| } | |
| else { | |
| Write-Host "Exiting..." | |
| exit | |
| } | |
| if ($selectedDevices.Count -eq 0) { | |
| Write-Host "No valid devices selected. Exiting." -ForegroundColor Yellow | |
| exit | |
| } | |
| # Confirm removal | |
| Write-Host "`nSelected devices to remove:" | |
| $selectedDevices | ForEach-Object { Write-Host "- $($_.FriendlyName)" } | |
| # Remove devices | |
| foreach ($device in $selectedDevices) { | |
| Write-Host "`nRemoving $($device.FriendlyName)..." | |
| pnputil /remove-device "$($device.InstanceId)" | |
| } | |
| Write-Host "`nDone. Some removals may require a reboot to fully complete." -ForegroundColor Green |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment