$ErrorActionPreference = 'Stop'

Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;

public static class BluetoothNative {
    [StructLayout(LayoutKind.Sequential)]
    public struct BLUETOOTH_ADDRESS {
        public ulong ullLong;
    }

    [DllImport("bthprops.cpl", SetLastError = true)]
    public static extern uint BluetoothRemoveDevice(ref BLUETOOTH_ADDRESS address);
}
'@

$address = New-Object BluetoothNative+BLUETOOTH_ADDRESS
$address.ullLong = [Convert]::ToUInt64('D011E51C23E8', 16)
$result = [BluetoothNative]::BluetoothRemoveDevice([ref]$address)
if ($result -notin 0, 1168) {
    throw "BluetoothRemoveDevice failed: $result"
}

Write-Output "pairing-removed:$result"
