Skip to content

Instantly share code, notes, and snippets.

@dhinakg
Created January 16, 2025 19:38
Show Gist options
  • Save dhinakg/084a9ab976dac5d56511691e672f6f35 to your computer and use it in GitHub Desktop.
Save dhinakg/084a9ab976dac5d56511691e672f6f35 to your computer and use it in GitHub Desktop.
Bluetooth VID/PID on Windows
# https://superuser.com/questions/1341997/using-a-uwp-api-namespace-in-powershell
# https://stackoverflow.com/questions/63505640/how-to-read-spd-deviceid-pnp-in-uwp-app-for-unpaired-device
# https://stackoverflow.com/questions/40950482/search-for-devices-in-range-of-bluetooth-uwp
$ErrorActionPreference = "Stop"
[Windows.Devices.Enumeration.DeviceInformation, Windows.Devices.Enumeration , ContentType = WindowsRuntime]
[Windows.Devices.Enumeration.DeviceInformationCollection, Windows.Devices.Enumeration , ContentType = WindowsRuntime]
Add-Type -AssemblyName System.Runtime.WindowsRuntime
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0]
Function Await($WinRtTask, $ResultType) {
$asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
$netTask = $asTask.Invoke($null, @($WinRtTask))
$netTask.Wait(-1) | Out-Null
$netTask.Result
}
Function AwaitAction($WinRtAction) {
$asTask = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and !$_.IsGenericMethod })[0]
$netTask = $asTask.Invoke($null, @($WinRtAction))
$netTask.Wait(-1) | Out-Null
}
$properties = [System.String[]]("System.ItemNameDisplay", "System.Devices.Aep.DeviceAddress", "System.DeviceInterface.Bluetooth.VendorId", "System.DeviceInterface.Bluetooth.ProductId")
$devices = Await([Windows.Devices.Enumeration.DeviceInformation]::FindAllAsync('System.Devices.DevObjectType:=5 AND System.Devices.Aep.ProtocolId:="{E0CBF06C-CD8B-4647-BB8A-263B43F0F974}"', $properties)) ([Windows.Devices.Enumeration.DeviceInformationCollection])
foreach ($device in $devices)
{
$device
$device.Properties
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment