Skip to content

Instantly share code, notes, and snippets.

@JasonKleban
Last active October 31, 2025 00:18
Show Gist options
  • Select an option

  • Save JasonKleban/f67a8b5ce393622f46445cdad4e5b8d0 to your computer and use it in GitHub Desktop.

Select an option

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
$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
@JasonKleban
Copy link
Author

JasonKleban commented Oct 30, 2025

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.

AdapterAddress : C8:...:38
FriendlyName   : Logi M650 L
MACAddress     : DB:...:8E
IRK            : 38...8C
LTK            : A9...F1
...

In Linux:

$ sudo -s
$ cd /var/lib/bluetooth/[AdapterAddress]
$ mv [MACAddress - 1] [MACAddress]            # Because pairing in Windows may have rotated the Mac Address 
$ nano [MACAddress]/info

Update the LTK and the IRK to match from Windows.
Run sudo systemctl restart bluetooth and the device should now be working in Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment