Lync and fortunes

lync1

“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 LyncSDKAssembliesDesktopMicrosoft.Lync.Model.DLL”

Import-Module $assemblyPath

 

#Initialize objects

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

$self = $client.Self;

 

#Get a fortune

$Fortunes = Get-Content c:tempfortunes.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)

$self.EndPublishContactInformation($ar)

 

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

Advertisements

One thought on “Lync and fortunes

  1. Pingback: Blog wrap-up » IT, IS, etc…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s