Monday, December 24, 2012

PowerShell to start Lync group conversation and send message

In previous blog post I had described how I wrote code for myself to achieve a personal task. As people says “Code for yourself before you code for others”, I took that opportunity to improve my life, before I go to solve problems and improve other’s life with my code. But did my problem solved with that small C# code?
I would say 50/50 .Its really difficult to add one more person on the go. I had to open the solution in VSTS then modify the list and run again. I can add users manually with less time than the time taken for Visual Studio to open. I love VS as developer.But as a user I hate as a user. Again keeping an app.config and editing it is equally time consuming like keeping a script which can also be edited on the fly. So what is best.
I would say script. More general PowerShell which has the capability to seamlessly interact with .net.In simple words its very easy to convert a C# / VB.Net code PS. Here goes the PS equivalent of what I posted last week in C#.
cls
$lyncDLLPath = “C:\Program Files\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.Lync.Model.DLL”
Import-Module $lyncDLLPath
$contactUris="sip:<email1>","sip:<email2>"
 
$client = [Microsoft.Lync.Model.LyncClient]::GetClient()

$conv = $client.ConversationManager.AddConversation()

foreach ($contactUri in $contactUris)
{
    $conv.AddParticipant($client.ContactManager.GetContactByUri($contactUri))
}
$m = $conv.Modalities[[Microsoft.Lync.Model.Conversation.ModalityTypes]::InstantMessage]
$m.BeginSendMessage("Hi guys this is Joy from Powershell,,,Shall we have lunch....", $null, $null);



1 comment:

bradcaccamo said...

nicely done. your example is about the best one i've seen.