Lync and fortunes


“Parachute for sale. Only used once, never opened, small stain”

“Life is tough. Get a helmet”

“I don’t have a smart phrase to share with you”

Some people love to put sentences like these in their messenger. I, for sure, do. In case of OCS, you could do it manually. But really, only one message of the day? Boooooring (catchphrase: “Somebody’s boring me … I think it’s me. ”), especially if you have collected lots of them. Changing them manually, almost as boring as not changing them. Spend some time to create a small program for that: that’s how we, geeks, do the stuff!

Anyway, I tried it with OCS, but had no luck. Either I was too lazy to find some simple solution or it wasn’t simple enough. But With the new releases the things are usually better then before (“If at first you don’t succeed, call it version 1.0”) and with Lync we have received a new SDK with the most precious peace of it, which finally allows to change the status programmatically Подмигивающая рожица

To cut long story short: you can read about the SDK parts which helped me to build the script, then read about PoSh scripting for Lync using the extensibility API and then read about how to operate the needed parameters. One more step – to download and install the SDK. After that you’ll be able to write your own script for that stuff.

Or you can just use this one:


#Load Assembly

$assemblyPath = "C:\Program Files (x86)\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.Lync.Model.DLL"

Import-Module $assemblyPath


#Initialize objects

$client = [Microsoft.Lync.Model.LyncClient]::GetClient()

$self = $client.Self;


#Get a fortune

$Fortunes = Get-Content c:\temp\fortunes.txt

$linesNumber = $Fortunes.Length

$todaysFortuneNumber = Get-Random Maximum $linesNumber Minimum 1

$todaysFortune = $Fortunes[$todaysFortuneNumber 1]


#Publish personal note of the local user

$contactInfo = new-object ‘System.Collections.Generic.Dictionary[Microsoft.Lync.Model.PublishableContactInformationType, object]’

$contactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::PersonalNote $todaysFortune)

$ar = $self.BeginPublishContactInformation($contactInfo, $null, $null)



The script isn’t ideal and needs improving, but you can consider it as a working prototype =)