32Feet.Net in Powershell

Hello! First of all, I am not a coder and second I struggled with this for 2 days before asking for help :slight_smile:

I am trying to programmatically pair 2 Bluetooth devices with PowerShell using the 32Feet.Net library (InTheHand.Net.Bluetooth). One is PIN-based and it is straight forward, but the 2nd one is using SSP.

I found this piece of code that it is supposed to do achieve this (I have bolded the important part):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InTheHand.Net.Bluetooth;
using System.Threading;

namespace BT
    class BluetoothAutoSSP
        public static void Main()
            BluetoothAutoSSP c = new BluetoothAutoSSP();

            EventHandler handler = new         EventHandler(c.handleRequests);
            BluetoothWin32Authentication authenticator = new BluetoothWin32Authentication(handler);

            while (true)

        public void handleRequests(Object thing, BluetoothWin32AuthenticationEventArgs args)
            args.Confirm = true;


Basically, a handler that will be called by BluetoothWin32Authentication and will set the Confirm parameter of BluetoothWin32AuthenticationEventArgs to true.
Below is the latest version (after hundreds of tries and changes) but the Powershell terminal crashes with “PowerShell has stopped working” so something must be wrong:

Add-Type -Path "InTheHand.Net.Personal.dll"

$cli = New-Object InTheHand.Net.Sockets.BluetoothClient
$devs = $cli.DiscoverDevices()
$dev = $devs | ? { $_.DeviceName -eq "XXXX" }

$handleRequests = {
param([object]$sender, [InTheHand.Net.Bluetooth.BluetoothWin32AuthenticationEventArgs]$sourceArgs)
$sourceArgs.Confirm = $true

$auth = [InTheHand.Net.Bluetooth.BluetoothWin32Authentication]::New($handleRequests)