Skip to content

Instantly share code, notes, and snippets.

@janegilring
Created August 8, 2013 06:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janegilring/6182174 to your computer and use it in GitHub Desktop.
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
#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