#skype4b #powershell Auto Enforce User-defined Lync/Skype Presence Status

Code sample to automatically maintain a user-defined Presence status in Lync / Skype for Business desktop client. Works even when the Windows computer is locked i.e. ignore PC lock and override Lync / Skype4b ‘s presence auto-reset.

Enjoy!


################################################################################
# Copyright (c) 201x-2017 leedesmond.com
# All Rights Reserved. Use at your own risk and responsibility.
# Set-Skype4bClientPresence.ps1
# Version 1.00
#
# REQUIREMENTS:
# Microsoft Lync 2013 SDK Client-side API
# (works with Skype for Business 2016/2015)
#
# Usage:
# Execute script in Windows PowerShell $profile to run as a separate process ...
# Start-Process -FilePath 'powershell.exe' -ArgumentList `
# "-NoProfile -Command Set-Skype4bClientPresence.ps1"
################################################################################
Import-Module "C:\Program Files (x86)\Microsoft Office\Office15\LyncSDK\Assemblies\Desktop\Microsoft.Lync.Controls.dll"
Import-Module "C:\Program Files (x86)\Microsoft Office\Office15\LyncSDK\Assemblies\Desktop\Microsoft.Lync.Model.dll"
while (1) {
$logonUI = $false;
try {
gps LogonUI -ea:Stop; $logonUI = $true;
} catch { }
#
try {
#3500 Available; 6500 Busy
$myAvailability = $myContact.GetContactInformation("Availability");
} catch {
#
try {
gps lync -ea:stop;
}
catch {
Start-Process -FilePath "c:\Program Files (x86)\Microsoft Office\Office16\lync.exe"
Start-Sleep -Seconds 5
}
$lc = [Microsoft.Lync.Model.LyncClient]::GetClient();
$mySipAddr = $lc.self.Contact.Uri;
$mySipAddr = $mySipAddr.SubString($mySipAddr.IndexOf(":")+1);
#
$myContact = $lc.ContactManager.GetContactByUri($mySipAddr);
$myAvailability = $myContact.GetContactInformation("Availability");
}
#
if ($myAvailability -eq [Microsoft.Lync.Controls.ContactAvailability]::Away -or ($logonUI)) {
$myAvailability = [Microsoft.Lync.Controls.ContactAvailability]::Busy;
$myContactInfo = New-Object 'System.Collections.Generic.Dictionary[Microsoft.Lync.Model.PublishableContactInformationType,object]';
$myContactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::Availability,$myAvailability);
#
$cInfo = $lc.self.BeginPublishContactInformation($myContactInfo,$null,$null);
$lc.self.EndPublishContactInformation($cInfo);
}
Start-Sleep -Seconds 5
} #while (1)

Bookmark the permalink.

Leave a Reply