Some days ago somebody asked via a comment to my blog entry about SwyxIt API and Powershell if it is possible to consume events from the API, e.g. to run a Powershell script when a call comes in. I tried it using the RCW interop.clmgrlib.dll which exposes the SwyxIt COM API as .Net Types. However, Powershell only supports a specific kind of delegates. A small script from the Powershell blog (get-delegate.ps1) seemed to help.
PS> [System.Reflection.Assembly]::LoadFrom("Interop.CLMGRLib.dll")
PS> $clmgr = new-object clmgrlib.clientlinemgrclass
PS> $cb = get-delegate clmgrlib.IClientLineMgrEventsDisp_DispOnLineMgrNotificationEventHandler {write-host $args }
PS> $clmgr.add_disponlinemgrnotification($cb)That gives no error, but the {write-host $args} script block is never called. I suppose it has something to do with different threads. Notifications are sent on separate threads and Powershell can't handle that.
Next I tried the PSEventing Powershell snapin. That seemed to work a little better, I could at least see that an event has been received. But Powershell crashes immediately after that. I don't know if it's PSEventing or the SwyxIt API wrapper.
There another approach I havn't tried yet: Host Powershell in an own application. A small program written in C# would use the SwyxIt API in the same way as IpPbxController (see download section) does. That program would host Powershell and execute the script.