Created
June 1, 2018 19:10
-
-
Save maravedi/d4e337435dd5a9d5722b21a9145eb353 to your computer and use it in GitHub Desktop.
PowerShell Script to Set Lync Personal Message Based on Day of Week
This file contains 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
# Script Name: Set-LyncPersonalMessage.ps1 | |
# Author: David Frazer | |
# Date Created: June 1st, 2018 | |
# | |
# I wrote this to be cute. My daughter is 3 and has special names for each day of the week. | |
# I thought it would be fun to have my Lync personal message be updated automatically based | |
# on the day of the week. | |
# | |
# This script requires that the Lync 2013 SDK be installed. | |
# For me, I have Skype for Business 2016, but the 2013 SDK works fine for it. | |
# Modify the $DLLPath variable based on the location of your DLLs. | |
# | |
# Usage: | |
# I use a VBScript wrapper to run this file at startup with a hidden window. | |
# Here is an example of that VBScript: | |
# CreateObject("Wscript.Shell").Run "PowerShell.exe -WindowStyle Hidden -File C:\Tools\Set-LyncPersonalMessage.ps1", 0, True | |
# | |
# Credit: | |
# I got the bits about Lync from here: https://stackoverflow.com/a/26316217/6721141 | |
# The rest is my own work. | |
# | |
# Note on Security: | |
# I sign my scripts, and use AllSigned as my execution policy. Therefore, if someone changed the hashes in this file, I'd know. | |
# I do validation on the DLL file checksums in an effort to prevent loading something other than what is expected. | |
# | |
[CmdletBinding()] | |
Param() | |
$Messages = @{ | |
"Sunday" = "Happy sun day!"; | |
"Monday" = "Happy moonday!"; | |
"Tuesday" = "Happy number two day!"; | |
"Wednesday" = "Happy wind day!"; | |
"Thursday" = "Happy hammer day!"; | |
"Friday" = "Happy french fry day!"; | |
"Saturday" = "Happy caturday!"; | |
} | |
$DayOfWeek = (Get-Date).DayOfWeek | |
$Message = $Messages.GetEnumerator() | Where-Object { $_.Name -eq $DayOfWeek } | Select -Expand Value | |
$DLLObject = @() | |
$DLLObject += [PSCustomObject] @{ | |
"Name" = "Microsoft.Lync.Controls.Dll"; | |
"Hash" = "F130EFF34A58E2D7EA65BC626DD2099A" | |
} | |
$DLLObject += [PSCustomObject] @{ | |
"Name" = "Microsoft.Lync.Model.Dll"; | |
"Hash" = "0DB348A2A4AF1CD673382FD559F5E81A" | |
} | |
$DLLPath = 'C:\Program Files (x86)\Microsoft Office 2013\LyncSDK\Assemblies\Desktop' | |
Foreach($DLL in $DLLObject) { | |
$ThisPath = "$DLLPath\$($DLL.Name)" | |
Try { | |
$Hash = Get-FileHash -Algorithm MD5 $ThisPath | |
} Catch { | |
Throw "Unable to get the file checksum of $ThisPath" | |
} | |
If($Hash.Hash -ne $DLL.Hash) { | |
Throw "Cannot validate the integrity of $ThisPath. File checksum not as expected: [Expected: $($DLL.Hash), Actual: $($Hash.Hash)]" | |
} | |
Try { | |
Import-Module $ThisPath | |
} Catch { | |
Throw "Unable to import the assembly: $ThisPath" | |
} | |
} | |
$Client = [Microsoft.Lync.Model.LyncClient]::GetClient() | |
$Self = $Client.Self | |
$ContactInfo = New-Object 'System.Collections.Generic.Dictionary[Microsoft.Lync.Model.PublishableContactInformationType, object]' | |
$ContactInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::PersonalNote, $Message) | |
$SetMessage = $Self.BeginPublishContactInformation($ContactInfo, $Null, $Null) | |
$Self.EndPublishContactInformation($SetMessage) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment