Created
August 5, 2025 12:06
-
-
Save Frank-Buss/e53d660d6f5568ca6fbf12ee69ff189f to your computer and use it in GitHub Desktop.
show Bluetooth adapter capabilities
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 Peripheral Mode Checker | |
# to execute powershell scripts, you might need to enable this first: | |
# Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process | |
Write-Host "=== Bluetooth Peripheral Mode Checker ===" -ForegroundColor Cyan | |
Write-Host "" | |
# Check for Bluetooth adapters | |
$usbBT = Get-PnpDevice -Class Bluetooth | Where-Object {$_.InstanceId -match "USB\\" -and $_.Status -eq "OK"} | |
if (-not $usbBT) { | |
Write-Host "No USB Bluetooth adapters found!" -ForegroundColor Red | |
return | |
} | |
Write-Host "Found USB Bluetooth adapter(s):" -ForegroundColor Green | |
$usbBT | ForEach-Object { Write-Host " - $($_.FriendlyName)" -ForegroundColor Cyan } | |
Write-Host "" | |
# Method that actually works in PowerShell | |
Write-Host "Checking Bluetooth capabilities..." -ForegroundColor Yellow | |
Add-Type -AssemblyName System.Runtime.WindowsRuntime | |
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | Where-Object { | |
$_.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 | |
} | |
try { | |
# Load the Bluetooth type | |
$null = [Windows.Devices.Bluetooth.BluetoothAdapter,Windows.Devices,ContentType=WindowsRuntime] | |
# Get default adapter | |
$asyncOp = [Windows.Devices.Bluetooth.BluetoothAdapter]::GetDefaultAsync() | |
$adapter = Await $asyncOp ([Windows.Devices.Bluetooth.BluetoothAdapter]) | |
if ($adapter) { | |
Write-Host "" | |
Write-Host "Adapter Information:" -ForegroundColor Green | |
Write-Host "===================" -ForegroundColor Green | |
Write-Host "Device ID: $($adapter.DeviceId)" | |
$macAddr = '{0:X12}' -f $adapter.BluetoothAddress | |
Write-Host "MAC Address: $($macAddr -replace '(.{2})(?!$)', '$1:')" | |
Write-Host "" | |
Write-Host "Capabilities:" -ForegroundColor Yellow | |
Write-Host "=============" -ForegroundColor Yellow | |
# The important property | |
$peripheralSupported = $adapter.IsPeripheralRoleSupported | |
$centralSupported = $adapter.IsCentralRoleSupported | |
$classicSupported = $adapter.IsClassicSupported | |
$leSupported = $adapter.IsLowEnergySupported | |
Write-Host "Peripheral Role Supported: " -NoNewline | |
if ($peripheralSupported) { | |
Write-Host "YES" -ForegroundColor Green -BackgroundColor DarkGreen | |
} else { | |
Write-Host "NO" -ForegroundColor Red -BackgroundColor DarkRed | |
} | |
Write-Host "Central Role Supported: " -NoNewline | |
if ($centralSupported) { | |
Write-Host "YES" -ForegroundColor Green | |
} else { | |
Write-Host "NO" -ForegroundColor Red | |
} | |
Write-Host "Classic Bluetooth: " -NoNewline | |
if ($classicSupported) { | |
Write-Host "YES" -ForegroundColor Green | |
} else { | |
Write-Host "NO" -ForegroundColor Red | |
} | |
Write-Host "Bluetooth LE: " -NoNewline | |
if ($leSupported) { | |
Write-Host "YES" -ForegroundColor Green | |
} else { | |
Write-Host "NO" -ForegroundColor Red | |
} | |
Write-Host "" | |
Write-Host "======================================" -ForegroundColor DarkGray | |
if ($peripheralSupported) { | |
Write-Host " RESULT: Peripheral mode IS supported " -ForegroundColor Black -BackgroundColor Green | |
Write-Host "======================================" -ForegroundColor DarkGray | |
Write-Host "This adapter can act as a BLE peripheral (GATT Server)" -ForegroundColor Green | |
} else { | |
Write-Host " RESULT: Peripheral mode NOT supported " -ForegroundColor White -BackgroundColor DarkRed | |
Write-Host "======================================" -ForegroundColor DarkGray | |
Write-Host "This adapter can only act as central/client" -ForegroundColor Red | |
} | |
} else { | |
Write-Host "No Bluetooth adapter could be accessed" -ForegroundColor Red | |
Write-Host "Make sure Bluetooth is enabled in Windows Settings" -ForegroundColor Yellow | |
} | |
} catch { | |
Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red | |
Write-Host "" | |
Write-Host "Make sure:" -ForegroundColor Yellow | |
Write-Host "- Bluetooth is enabled in Windows Settings" | |
Write-Host "- You're running Windows 10 version 1703 or later" | |
Write-Host "- The Bluetooth adapter is properly installed" | |
} | |
# Windows version check | |
Write-Host "" | |
Write-Host "System Information:" -ForegroundColor Yellow | |
$build = [System.Environment]::OSVersion.Version.Build | |
Write-Host "Windows Build: $build" | |
if ($build -ge 15063) { | |
Write-Host "Windows version supports BLE peripheral (1703+)" -ForegroundColor Green | |
} else { | |
Write-Host "Windows version too old for peripheral mode" -ForegroundColor Red | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment