Last active
October 31, 2025 00:18
-
-
Save JasonKleban/f67a8b5ce393622f46445cdad4e5b8d0 to your computer and use it in GitHub Desktop.
Windows 11 Admin-Powershell 1-liner to extract Bluetooth Mouse, Keyboard, Audio pairing keys to share with dual-boot linux
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
| $DeviceNamePattern = "Logi M650*"; ` | |
| $Outfile = "C:\bluetooth_device_keys.txt"; ` | |
| $Command = "powershell.exe"; ` | |
| $ScriptCommand = "" + ` | |
| "Get-PnpDevice -Class 'Bluetooth' | ? FriendlyName -like '$DeviceNamePattern' " + ` | |
| " | Select " + ` | |
| "FriendlyName, " + ` | |
| "@{N='MACAddress';E={Get-PnpDeviceProperty -InstanceId `$_.InstanceID | ? {`$_.KeyName -eq 'DEVPKEY_Bluetooth_DeviceAddress'} | Select -ExpandProperty Data }}" + ` | |
| "|% { `$device = `$_;" + ` | |
| "Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys -Recurse | ? {(Split-Path `$_.Name -Leaf) -eq `$device.MACAddress} " + ` | |
| "| Select " + ` | |
| "@{N='AdapterAddress';E={(Split-Path `$_.PSParentPath -Leaf).ToUpperInvariant() -replace '..(?!$)', '$&:'}}, " + ` | |
| "@{N='FriendlyName';E={`$device.FriendlyName}}, " + ` | |
| "@{N='MACAddress';E={`$device.MACAddress.ToUpperInvariant() -replace '..(?!$)', '$&:'}}, " + ` | |
| "@{N='IRK'; E={(`$_.GetValue('IRK') | % { `$_.ToString('X2') }) -join ''}}, " + ` | |
| "@{N='LTK'; E={(`$_.GetValue('LTK') | % { `$_.ToString('X2') }) -join ''}} " + ` | |
| "| Format-List } " + ` | |
| "| Out-File -FilePath '$Outfile'"; ` | |
| $Arguments = "-command `"& { $ScriptCommand }`""; ` | |
| Import-Module ScheduledTasks; ` | |
| $name = "RunAs_LocalSystem_$(New-Guid)"; ` | |
| $actionArguments = @{ '-Execute' = $Command; }; ` | |
| if (-not [string]::IsNullOrEmpty($Arguments)) { $actionArguments['-Argument'] = $Arguments } ` | |
| $action = New-ScheduledTaskAction @actionArguments; ` | |
| $principal = New-ScheduledTaskPrincipal -UserId 'NT AUTHORITY\SYSTEM' -LogonType Interactive; ` | |
| Register-ScheduledTask -TaskName $name -Action $action -Principal $principal | Start-ScheduledTask; ` | |
| Unregister-ScheduledTask $name -Confirm:$false |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pair first in Linux, then pair in Windows.
Paste that one-liner into an admin powershell and get something like this for each name-pattern-matched device.
In Linux:
Update the LTK and the IRK to match from Windows.
Run
sudo systemctl restart bluetoothand the device should now be working in Linux.