Created
August 8, 2013 06:54
-
-
Save janegilring/6182174 to your computer and use it in GitHub Desktop.
The purpose of Publish-LyncContactInformation is to demonstrate how PowerShell can be used to interact with the Lync SDK. For more information, see the related blog post at blog.powershell.no
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -version 2.0 | |
function Publish-LyncContactInformation { | |
<# | |
.Synopsis | |
Publish-LyncContactInformation is a PowerShell function to configure a set of settings in the Microsoft Lync client. | |
.DESCRIPTION | |
The purpose of Publish-LyncContactInformation is to demonstrate how PowerShell can be used to interact with the Lync SDK. | |
Tested with Lync 2013 only. | |
Prerequisites: Lync 2013 SDK - http://www.microsoft.com/en-us/download/details.aspx?id=36824 | |
.EXAMPLE | |
Publish-LyncContactInformation -Availability Available | |
.EXAMPLE | |
Publish-LyncContactInformation -Availability Away | |
.EXAMPLE | |
Publish-LyncContactInformation -Availability "Off Work" -ActivityId off-work | |
.EXAMPLE | |
Publish-LyncContactInformation -PersonalNote test | |
.EXAMPLE | |
Publish-LyncContactInformation -Availability Available -PersonalNote ("Quote of the day: " + (Get-QOTD)) | |
.EXAMPLE | |
Publish-LyncContactInformation -Location Work | |
.NOTES | |
For more information, see the related blog post at blog.powershell.no | |
.FUNCTIONALITY | |
Provides a function to configure Availability, ActivityId and PersonalNote for the Microsoft Lync client. | |
#> | |
Param | |
( | |
# Availability state as string | |
[ValidateSet("Appear Offline","Available","Away","Busy","Do Not Disturb","Be Right Back","Off Work")] | |
[string] | |
$Availability, | |
# ActivityId as string | |
[string] | |
$ActivityId, | |
# String value to be configured as personal note in the Lync client | |
[string] | |
$PersonalNote, | |
# String value to be configured as location in the Lync client | |
[string] | |
$Location | |
) | |
if (-not (Get-Module -Name Microsoft.Lync.Model)) { | |
try { | |
Import-Module -Name (Join-Path -Path ${env:ProgramFiles(x86)} -ChildPath "Microsoft Office\Office15\LyncSDK\Assemblies\Desktop\Microsoft.Lync.Model.dll") -ErrorAction Stop | |
} | |
catch { | |
Write-Warning "Microsoft.Lync.Model not available, download and install the Lync 2013 SDK http://www.microsoft.com/en-us/download/details.aspx?id=36824" | |
break | |
} | |
} | |
$Client = [Microsoft.Lync.Model.LyncClient]::GetClient() | |
if ($Client.State -eq "SignedIn") { | |
$Self = $Client.Self | |
$ContactInfo = New-Object 'System.Collections.Generic.Dictionary[Microsoft.Lync.Model.PublishableContactInformationType, object]' | |
switch ($Availability) | |
{ | |
"Available" {$AvailabilityId = 3000} | |
"Appear Offline" {$AvailabilityId = 18000} | |
"Away" {$AvailabilityId = 15000} | |
"Busy" {$AvailabilityId = 6000} | |
"Do Not Disturb" {$AvailabilityId = 9000} | |
"Be Right Back" {$AvailabilityId = 12000} | |
"Off Work" {$AvailabilityId = 15500} | |
} | |
if ($Availability) { | |
$ContactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::Availability, $AvailabilityId) | |
} | |
if ($ActivityId) { | |
$ContactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::ActivityId, $ActivityId) | |
} | |
if ($PersonalNote) { | |
$ContactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::PersonalNote, $PersonalNote) | |
} | |
if ($Location) { | |
$ContactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::LocationName, $Location) | |
} | |
if ($ContactInfo.Count -gt 0) { | |
$Publish = $Self.BeginPublishContactInformation($ContactInfo, $null, $null) | |
$self.EndPublishContactInformation($Publish) | |
} else { | |
Write-Warning "No options supplied, no action was performed" | |
} | |
} else { | |
Write-Warning "Lync is not running or signed in, no action was performed" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment