I'm trying to create a PowerShell script that will send a Lync message to all users in column "A" the text in columns "B" and "C".
I started out using this guide- http://blogs.technet.com/b/csps/archive/2011/05/05/sendim.aspx
I believe I have most of the framework down, but my main issue is figuring out how to actually IM the user. When I run my script I get-
Cannot find an overload for "AddParticipant" and the argument count: "1".
Here's the code I'm using-
Function MassIM
{
Try
{
$AssemblyPath = “C:\Program Files (x86)\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.Lync.Model.DLL”
Import-Module $AssemblyPath
}
Catch [System.Exception]
{
$TS = TimeStamp
"Could not load required DLL files" | OutputToError
FatalError
}
Try
{
$LyncClient = [Microsoft.Lync.Model.LyncClient]::GetClient()
}
Catch [System.Exception]
{
$TS = TimeStamp
"Could not connect to Lync client." | OutputToError
FatalError
}
Try
{
$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $False
}
Catch [System.Exception]
{
$TS = TimeStamp
"Could not load Excel." | OutputToError
FatalError
}
Try
{
$IMBook = $Excel.Workbooks.Open("C:\Users\cbrady-sa\Desktop\MassIM\List\IMList.xls")
}
Catch [System.Exception]
{
$TS = TimeStamp
"Could not open required workbook." | OutputToError
FatalError
}
Try
{
$IMSheet = $IMBook.Worksheets.Item(1)
}
Catch [System.Exception]
{
$TS = TimeStamp
"Could not open required worksheet." | OutputToError
FatalError
}
$FoundEmptyCell = $False
$Row = 1
While (!$FoundEmptyCell)
{
If ($IMSheet.Cells.Item($Row, 1).Value() -EQ $null)
{
$FoundEmptyCell = $True
}
Else
{
Try
{
$User = $IMSheet.Cells.Item($Row, 1).Value()
$UserDesk = $IMSheet.Cells.Item($Row, 2).Value()
$UserExt = $IMSheet.Cells.Item($Row, 3).Value()
}
Catch [System.Exception]
{
$TS = TimeStamp
"Could not load data from worksheet." | OutputToError
FatalError
}
Try
{
$User = $User -split ','
$UserName = $User[1] + "." + $User[0] + "@xxx.com"
$UserName.Trim()
$Convo = $LyncClient.ConversationManager.AddConversation()
$MSG = New-Object "System.Collections.Generic.Dictionary[Microsoft.Lync.Model.Conversation.InstantMessageContentType,String]"
$Mod = $Convo.Modalities[1]
$Convo.AddParticipant($UserName)
$MSG.Add(0, "Hello ${UserName}. Is your desk still ${UserDesk}? Is your extension still ${UserExt}?")
$null = $Mod.BeginSendMessage($MSG, $null, $MSG)
}
Catch [System.Exception]
{
$TS = TimeStamp
"Could not instant message${UserName}." | OutputToError
$Error | OutputToError
}
$Row++
}
}
$Excel.Quit()
}
Not sure why this isn't working; every guide I look at online seems to match what I have for the most part. Can't for the life of me figure out why I'm getting that error. This question appears similar but it has no real solution: Exception calling "BeginSendMessage" with "3" argument(s): "Value does not fall within the expected range."
Any help is immensely appreciated.