Create a gist now

Instantly share code, notes, and snippets.

An example on how to schedule the Publish-LyncContactInformation function using Register-ScheduledJob introduced in Windows PowerShell 3.0
$cred = Get-Credential
Register-ScheduledJob -Name "Publish-LyncContactInformation - Available" -ScriptBlock {
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"
}
}
Publish-LyncContactInformation -Availability Available -PersonalNote ("Quote of the day: " + (Get-QOTD))
} -Trigger (New-JobTrigger -DaysOfWeek Monday,Tuesday,Wednesday,Thursday,Friday -Weekly -At 08:00) -ScheduledJobOption (New-ScheduledJobOption -RequireNetwork) -Credential $cred
Register-ScheduledJob -Name "Publish-LyncContactInformation - Off Work" -ScriptBlock {
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"
}
}
Publish-LyncContactInformation -Availability "Off Work" -ActivityId off-work
} -Trigger (New-JobTrigger -DaysOfWeek Monday,Tuesday,Wednesday,Thursday,Friday -Weekly -At 16:00) -ScheduledJobOption (New-ScheduledJobOption -RequireNetwork) -Credential $cred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment