Parallel Universe - MS Tech Blog

The ramblings of a PFE

Update your Lync Note with a Quote of the Day – API Powershell

Update your Lync Note with a Quote of the Day – API Powershell

  • Comments 6
  • Likes

 

Following on playing with the API this script is just for fun. I have created a scheduled task that runs daily and updates the quote of the day for my Lync note…. have fun!

p.s it requires internet access!

Here is the sample code

image

and here is my updated Lync Client

 

image

 

here is the code so copy and paste

#Load Assembly
$assemblyPath = “C:\Program Files (x86)\Microsoft Office 2013\LyncSDK\Assemblies\Desktop\Microsoft.Lync.Model.DLL”
Import-Module $assemblyPath
$client = [Microsoft.Lync.Model.LyncClient]::GetClient()

#Get Qoute of the Day
$url = "http://feeds.feedburner.com/brainyquote/QUOTEBR"
$data = Invoke-RestMethod -Uri $url
$qotd = $data[0].description

#Publish QoTD to Note
$instanceSelf = $Client.Self
$noteInfo = New-Object 'System.Collections.Generic.Dictionary[Microsoft.Lync.Model.PublishableContactInformationType, object]'
$noteInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::PersonalNote, $qotd)
$Publishnote = $instanceSelf.BeginPublishContactInformation($noteInfo, $null, $null)
$instanceself.EndPublishContactInformation($Publishnote)

Comments
  • cool stuff thanks

  • Where do i put this code in? Do I save it somewhere? thanks for sharing!!

  • Peter: It's PowerShell code. Use MS PowerShell to execute it.

  • Can I do the same with Lync 2010? If yes, please advice, the files Microsoft.Lync.Model.DLL is in a Zip file :'(

  • Guys, I have a proxy which needs authentication so get the following error :

    Invoke-RestMethod :
    Access Denied (authentication_failed)
    Your credentials could not be authenticated: "Credentials are missing.". You will not be permitted access until your
    credentials can be verified.
    This is typically caused by an incorrect username and/or password, but could also be caused by network problems.
    At line:1 char:9
    + $data = Invoke-RestMethod -Uri $url
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
    eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

    Can you tell me a way round this or whats missing so that it can prompt me to use the proxy ?

    Thanks

    Dave.,

  • Am getting an error while trying it to run it on mS poweshell and tht error is:

    Import-Module : The specified module 'C:\Program Files (x86)\Microsoft Office 2013\LyncSDK\Assemblies\Desktop\Microsoft.Lync.Model.DLL' was not loaded because no valid module file was
    found in any module directory.
    At line:3 char:14
    + Import-Module <<<< $assemblyPath
    + CategoryInfo : ResourceUnavailable: (C:\Program File....Lync.Model.DLL:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

    Unable to find type [Microsoft.Lync.Model.LyncClient]: make sure that the assembly containing this type is loaded.
    At line:4 char:44
    + $client = [Microsoft.Lync.Model.LyncClient] <<<< ::GetClient()
    + CategoryInfo : InvalidOperation: (Microsoft.Lync.Model.LyncClient:String) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

    The term 'Invoke-RestMethod' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify t
    hat the path is correct and try again.
    At line:8 char:26
    + $data = Invoke-RestMethod <<<< -Uri $url
    + CategoryInfo : ObjectNotFound: (Invoke-RestMethod:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    Cannot index into a null array.
    At line:9 char:15
    + $qotd = $data[ <<<< 0].description
    + CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment