Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change status of Lync by script

Tags:

lync-2010

Is it possible to change status of Microsoft Lync 2010 by script?

I want Script which works on Win XP and change status to available after fixed interval.Tried to search in internet but was not successful in finding one.

like image 951
Mayank Jain Avatar asked Apr 25 '13 11:04

Mayank Jain


4 Answers

For Lync 2013 this PowerShell script works. You'll need to install the Lync 2013 SDK first. The SDK installer might say you need to install Silverlight 4, but don't worry about that, it's not necessary.

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Confirm:$false
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser -Confirm:$false

Import-Module "C:\Program Files\Microsoft Office\Office15\LyncSDK\Assemblies\Desktop\Microsoft.Lync.Model.dll"
Import-Module "C:\Program Files\Microsoft Office\Office15\LyncSDK\Assemblies\Desktop\Microsoft.Lync.Controls.dll"

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

$availability = [Microsoft.Lync.Controls.ContactAvailability]::Away

$contactInfo = (New-Object "System.Collections.Generic.Dictionary[Microsoft.Lync.Model.PublishableContactInformationType,object]") -As "System.Collections.Generic.IEnumerable[System.Collections.Generic.KeyValuePair[Microsoft.Lync.Model.PublishableContactInformationType,object]]"
$contactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::Availability, $availability)

$ar = $client.Self.BeginPublishContactInformation($contactInfo, [System.AsyncCallback]$null, [object]$null)
$client.Self.EndPublishContactInformation($ar)

That sets the status to "Appear Away", but you can change [Microsoft.Lync.Controls.ContactAvailability]::Away into this [Microsoft.Lync.Controls.ContactAvailability]::None to reset the status.

like image 66
intrepidis Avatar answered Oct 22 '22 20:10

intrepidis


According to the documentation, the Lync binary does not offer that feature. However, you could use the Lync SDK to achieve what you want by writing a small helper application (or incorporating the relevant code in your current application).

According to an MVP in the Microsoft forums, this also is not available out-of-the-box.

However, according to the documentation, a PowerShell script like this one should be able to do the trick:

import-module "C:\Program Files (x86)\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.Lync.Controls.Dll"

$availability = [Microsoft.Lync.Controls.ContactAvailability]::Available

$contactInfo = new-object 'System.Collections.Generic.Dictionary[Microsoft.Lync.Model.PublishableContactInformationType, object]'
$contactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::Availability, 
                $availability)

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

This script requires the Lync SDK or the Lync SDK redistributable to be installed.

Much of this information has been taken from here.

like image 31
likeitlikeit Avatar answered Oct 22 '22 21:10

likeitlikeit


The above post does not work. More DLL modules are needed. But i've made the following changes below so it works. Then you can use TaskSch to get it to run automatically. Still needs the 2010 Lync SDK installing.

Set 15550 to mean 'Off-Work' not 'Away'. More useful.

See - http://blogs.technet.com/b/heyscriptingguy/archive/2012/08/11/weekend-scripter-use-the-windows-task-scheduler-to-run-a-windows-powershell-script.aspx

Note this code does not check if LYNC is signed in. If it is not it will not run.

import-module "C:\Program Files (x86)\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.Lync.Controls.Dll"
import-module "C:\Program Files (x86)\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.Lync.Model.Dll"

# Obtain the entry point to the Lync.Model API
$client = [Microsoft.Lync.Model.LyncClient]::GetClient()

$self = $client.Self;

#Set Details of Personal Note and Availability
#Useful availability codes for use below - 3500 Available, 15500 Away (converted to "Off Work" in this script by setting activity ID), 6500 Busy, 9500 Do not disturb, 12000 Be Right Back) 
$availability = 3500
$date = [DateTime]::Now
$message = "Remote Work. UK Time +5 hours EST (US), -5.5 IST (India). Availability script last run $date"

#Publish personal note and presence availability of the local user
$contactInfo = new-object 'System.Collections.Generic.Dictionary[Microsoft.Lync.Model.PublishableContactInformationType, object]'
$contactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::PersonalNote, 
            $message)
$contactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::Availability, 
            $availability)
If ($availability -eq 15500) {$contactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::ActivityId, 
            "off-work")}

$ar = $self.BeginPublishContactInformation($contactInfo, $null, $null)
$self.EndPublishContactInformation($ar)
like image 35
Pete Avatar answered Oct 22 '22 21:10

Pete


Ok - This is what I did

  1. Install 2013 SDK (This works with Skype for Business too BTW)
  2. use the code from Pete above except change the assemblies directories to C:\Program Files (x86)\Microsoft Office\Office15\LyncSDK\Assemblies\Desktop\ for both of those
  3. I had to add config files per this page (run as administrator http://tfl09.blogspot.com/2010/08/using-newer-versions-of-net-with.html
  4. Change the message in the script of Pete's
  5. Automate with Task Scheduler the .ps1 script
like image 28
Tom Stickel Avatar answered Oct 22 '22 20:10

Tom Stickel