Send Lync Instant Message with the PowerShell script

Introduction

This script will send an Instant Message to Lync Client Contact for User.

Scenarios

This script is to help users to send Instant Message via PowerShell when they are inconvenient with Lync Client UI.

Script

This script contains one advanced function Send-OSCLyncInstantMessage, you can use this script in the following ways:

Step1: Prerequisite before running this script.

Step2: Start Lync Client 2010 and Log in

Step3: Run the script in the Lync Server Management Shell, type the one command: Import-Module <Script Path> at the prompt.

For example, type Import-Module C:\Script\SendLyncInstantMessage.psm1

Here are some code snippets for your references.

PowerShell
Edit|Remove
#Start Conversation 
$msg = New-Object "System.Collections.Generic.Dictionary[Microsoft.Lync.Model.Conversation.InstantMessageContentType,String]" 
#Add the Message 
$msg.Add(0,$message) 
#choose Modality Type 
$Modality = $Conversation.Modalities[1] 
#Start the Dialog  
$null = $Modality.BeginSendMessage($msg, $null, $msg) 
#Send the Message  
$null = $Modality.BeginSendMessage($msg, $null, $msg)

Examples

Example 1: Send a Plain Text Instant Message "Test" to User1 on your Lync Client Contact List..
Command: Send-OSCLyncInstantMessage -Alias User1 -Message "Test"
Screenshot:

Example 2: Send a Plain Text Instant Message "Test" to User1 and User2 on your Lync Client Contact List..
Command: Send-OSCLyncInstantMessage -Alias User1,User2 -Message "Test"
Screenshot:

Prerequisite

Lync Client 2010
PowerShell 2.0