Lync Client, PowerShell, Scripting
comments 5

Auto answering incoming calls in Lync using PowerShell

In the last post, I gave a brief introduction to Lync 2010 SDK for client side automation. And, then I showed an example of quickly accessing Lync client objects for setting status text and availability. In today’s post, let us look at a simple script that combines PowerShell eventing and Lync conversation events to auto-answer an incoming Lync call.

If you don’t have Lync SDK installed (it comes with a lot of unnecessary baggage), you can just copy the model DLL at “C:\Program Files (x86)\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.Lync.Model.Dll” from a machine that has Lync SDK installed. This should be sufficient for the task outlined in this post.

Without further delay, here is the code to achieve what I just said:

This is it. After you run this code snippet (don’t forget the event subscriptions using Register-ObjectEvent cmdlet are only available in the current PS session), all your Lync calls get auto-answered. Now, why would anyone on earth do that? Well, that is a great question. There is no need in fact. This is just a pre-cursor to what is coming up. I am trying to introduce the concepts using these sample code snippets and then towards the end, we shall build a simple module or script that helps us achieve more than what you see here today.

With that thought, let us get back to the above code.

First, I used the ConversationAdded event to notify me whenever someone calls me or even sends an instant message. So, when the event gets fired (means someone either called you or messaged you on Lync), we get an instance of the Conversation namespace to play with. Within Lync, each conversation type has a modality associated with it. For example, we have different modalities such as InstantMessage and AudioVideo.

In the above code snippet, I am assuming that the incoming conversation is always AudioVideo and is blindly accepting the incoming conversation. This may result in an error if the incoming conversation isn’t AudioVideo. There are ways to find the type of an incoming conversation. This is one thing we will explore more in the upcoming posts.

Also, the code snippet above accepts incoming calls from anyone. Now, this is not something we may want to do. The Conversation namespace also offers a participants property which can be used to identify who is calling us. The participant.IsSelf tells us if a participant in the Conversation object is the local client. Again, more on this in the next post.

Finally, I have used the event details within the -Action script block to accept the call. This completely depends on the modality type. You can check out this method definition here.

Hope this helps. I will start diving deep into some of these namespaces in the upcoming posts. Until then, have a good time.


Filed under: Lync Client, PowerShell, Scripting


Ravikanth is a principal engineer and the lead architect for Microsoft and VMware virtualized and hybrid cloud solutions within the Infrastructure Solutions Group at Dell EMC. He is a multi-year recipient of Microsoft Most Valuable Professional (MVP) award in Windows PowerShell (CDM) and Microsoft Azure. Ravikanth is the author of Windows PowerShell Desired State Configuration Revealed (Apress) and leads Bangalore PowerShell and Bangalore IT Pro user groups. He can be seen speaking regularly at local user group events and conferences in India and abroad.