{"id":79745,"date":"2016-08-19T00:01:39","date_gmt":"2016-08-19T07:01:39","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=79745"},"modified":"2019-02-18T09:10:28","modified_gmt":"2019-02-18T16:10:28","slug":"use-powershell-to-integrate-with-the-lync-2013-sdk-for-skype-for-business-part-1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-integrate-with-the-lync-2013-sdk-for-skype-for-business-part-1\/","title":{"rendered":"Use PowerShell to integrate with the Lync 2013 SDK for Skype for Business \u2013 Part 1"},"content":{"rendered":"<p><strong>Summary<\/strong>: Get started with the Lync 2013 SDK by using PowerShell to manage Skype for Business 2016 client.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/> How do I integrate Windows PowerShell with the Lync SDK to manage Skype For Business client?<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/> MVP Chendrayan Venkatesan is back again to show us how to get started with the Lync 2013 SDK and do some really cool stuff with PowerShell and Skype for Business!<\/p>\n<p>Take it away, Chen!<\/p>\n<p>The Skype for Business 2016 client helps you stay connected with known people by using instant messaging, audio, video call, email, persistent chat rooms, online meetings, and presentations. By using Skype for Business, you can send IM or call a known person, which saves time at work. Some organizations might have built customized Skype for Business client applications or integrated Skype for Business with custom applications for their business needs.<\/p>\n<p>This blog post shares insights about how to extend PowerShell with the Lync SDK to explore Skype for Business 2016 client. Why should you use the Lync SDK for the Skype for Business client? Because there is no Skype for Business application API released for Windows. However, the Lync 2013 SDK (client) is fully supported for Lync 2013, Skype for Business, and Skype for Business online.<\/p>\n<ul>\n<li><a target=\"_blank\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/office\/jj933180.aspx?f=255&amp;MSPPError=-2147217396\">Lync 2013 SDK documentation<\/a><\/li>\n<li><a target=\"_blank\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/office\/jj933215.aspx?f=255&amp;MSPPError=-2147217396\">Get started with Lync 2013 SDK<\/a><\/li>\n<li><a target=\"_blank\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/office\/jj933215.aspx#Do\">What can you do with Lync 2013 SDK?<\/a><\/li>\n<\/ul>\n<p>All the previous articles are focused for software developers, but what can system administrators can do with the Lync 2013 SDK to work with Skype for Business client? Well, the answer is: A lot more by using PowerShell<strong>.<\/strong><\/p>\n<p style=\"padding-left: 30px\"><strong>Note<\/strong>: Install Lync 2013 SDK <strong>only if required<\/strong>. Its available in the <a target=\"_blank\" href=\"https:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=36824\">Microsoft Download Center<\/a>.<\/p>\n<p>The system requirements to install the Lync SDK are a real challenge. Yes, the Lync 2013 SDK will look for Lync 2013 client and Visual Studio 2010 components, which you don\u2019t want to install. To bypass it, we came up with a small tweak which follows.<\/p>\n<ol>\n<li>Download the <a target=\"_blank\" href=\"https:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=36824\">LyncSDK.exe<\/a>.<\/li>\n<li>Extract the file using 7Zip.<\/li>\n<li>Now, you see the Lync SDK folder, which has a security catalog file and two Windows installer files. Choose the appropriate version, 64- or 32-bit.<\/li>\n<li>Install the MSI package, and confirm the installation in Control Panel.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1-HSG-081916.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1-HSG-081916.png\" alt=\"Screenshot of the Microsoft Office Lync Software Development Kit in the .zip file.\" width=\"556\" height=\"139\" class=\"alignnone size-full wp-image-79755\" \/><\/a><\/p>\n<p>The 32-bit Lync SDK will be located at C:\\Program Files (x86)\\Microsoft Office 2013\\LyncSDK<strong> \u00a0<\/strong>and contains folders for Assemblies, Redist , samples, LyncClientSDK help, and redist help file.<\/p>\n<p>Now you\u2019re partially set to start exploring Skype for Business 2016 client features by using PowerShell and the Lync SDK assembly (Microsoft.Lync.Model.dll) from the Desktop folder.<\/p>\n<p>To begin, you need to load the assembly in PowerShell by executing one of the following snippets and ensure that you\u2019re signed in to Skype for Business. Here is the <a target=\"_blank\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.lync.model.lyncclient_di_3_uc_ocs14mreflyncclnt.aspx\">Lync client class<\/a> documentation for reference.<\/p>\n<p style=\"padding-left: 60px\"><code>Import-Module \"C:\\Program Files (x86)\\Microsoft Office 2013\\LyncSDK\\Assemblies\\Desktop\\Microsoft.Lync.Model.dll\"<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>$Client = [Microsoft.Lync.Model.LyncClient]::GetClient()<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>$Client<\/code><\/p>\n<p>&#8212;\u00a0or &#8212;<\/p>\n<p style=\"padding-left: 60px\"><code>$assembly = \"C:\\Program Files (x86)\\Microsoft Office 2013\\LyncSDK\\Assemblies\\Desktop\\Microsoft.Lync.Model.dll\"<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>Import-Module $assembly<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>$Client<\/code><\/p>\n<p>Here\u2019s the output. The uri property is removed to avoid exposing our domain information.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2-HSG-081916.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2-HSG-081916.png\" alt=\"Screenshot of the output after loading assembly.\" width=\"650\" height=\"120\" class=\"alignnone size-full wp-image-79775\" \/><\/a><\/p>\n<p>How does this work? <strong>Microsoft.Lync.Model.LyncClient<\/strong> implements the client class, which is the main entry point for the API, and provides access to conversations and contacts by using the <strong>conversationmanger<\/strong> and <strong>contactmanager<\/strong> classes respectively. <strong>GetClient()<\/strong> and <strong>GetAutomation()<\/strong> are the static methods of the Lync client class. To get the static methods, use the following code:<\/p>\n<p style=\"padding-left: 60px\"><code>[Microsoft.Lync.Model.LyncClient] | GM -Static<\/code><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3-HSG-081916.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3-HSG-081916.png\" alt=\"Screenshot of static methods.\" width=\"579\" height=\"128\" class=\"alignnone size-full wp-image-79785\" \/><\/a><\/p>\n<p>Let\u2019s park the <strong>GetAutomation<\/strong> method for future blog posts and focus on the <strong>GetClient<\/strong> static method. After the successful execution of the following snippet, the <strong>$Client<\/strong> variable holds the Lync client object, which is all we need for our demo.<\/p>\n<p style=\"padding-left: 60px\"><code>$Client = [Microsoft.Lync.Model.LyncClient]::GetClient()<\/code><\/p>\n<p>Now, let us see the available properties, events, and methods of the Lync client class by using PowerShell.<\/p>\n<p style=\"padding-left: 60px\"><code>$Client = [Microsoft.Lync.Model.LyncClient]::GetClient()<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>$Client | GM -MemberType Properties | Select Name , MemberType<\/code><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4-HSG-081916.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4-HSG-081916.png\" alt=\"Screenshot of output of the properties of the Lync client class.\" width=\"510\" height=\"174\" class=\"alignnone size-full wp-image-79795\" \/><\/a><\/p>\n<p style=\"padding-left: 60px\"><code>$Client = [Microsoft.Lync.Model.LyncClient]::GetClient()<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>$Client | GM -MemberType Event | Select Name , MemberType<\/code><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5-HSG-081916.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5-HSG-081916.png\" alt=\"Screenshot of output of the events of the Lync client class.\" width=\"518\" height=\"111\" class=\"alignnone size-full wp-image-79805\" \/><\/a><\/p>\n<p style=\"padding-left: 60px\"><code>$Client = [Microsoft.Lync.Model.LyncClient]::GetClient()<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>$Client | GM -MemberType Method | Select Name , MemberType<\/code><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6-HSG-081916.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6-HSG-081916.png\" alt=\"Screenshot of output of the properties of the Lync client class.\" width=\"526\" height=\"186\" class=\"alignnone size-full wp-image-79815\" \/><\/a><\/p>\n<p>Note: <a target=\"_blank\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/office\/hh243705(v=office.14).aspx\">PowerShell Scripting Lync 2010 Using Lync Mode API<\/a> examples are worth reading if you\u2019re interested in using Lync 2010 client at your work place.<\/p>\n<p>Let\u2019s see an example script that allows users to sign in to Skype for Business with a fancy personal note and custom presence while signing in to let users choose the status like Free, Away, Busy etc. Download the full script from the <a target=\"_blank\" href=\"https:\/\/gallery.technet.microsoft.com\/Sign-in-to-Skype-for-de8c7666\/file\/158002\/1\/Publish-xSKBClient.ps1\">TechNet Script Gallery<\/a> and save it. In our case, we saved the script at C:\\Scripts\\Publish-xSKBClient by using the dot sourcing operator call in the script as you see in the following screenshot. If you are already signed in to the Skype for Business, client the script will publish the presence and update the personal note.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7-HSG-081916.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7-HSG-081916.png\" alt=\"PS C:\\Scripts&gt; . .\\Publish-xSKBClient.ps1\" width=\"565\" height=\"23\" class=\"alignnone size-full wp-image-79825\" \/><\/a><\/p>\n<p>That\u2019s it! We\u2019re good to test the <strong>Publish-xSKBClient<\/strong>.<\/p>\n<p style=\"padding-left: 60px\"><code>#region Busy<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>Publish-xSKBClient -Uri \"someone@domain.com\" -SignInAs Busy -PersonalNote \"We Love PowerShell!\"<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>#endregion<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>#region Away<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>Publish-xSKBClient -Uri \"someone@domain.com\" -SignInAs Away -PersonalNote \"We Love PowerShell!\"<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>#endregion<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>#region DoNotDisturb<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>Publish-xSKBClient -Uri \"someone@domain.com\" -SignInAs DoNotDisturb -PersonalNote \"We Love PowerShell!\"<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>#endregion<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>#region Login with Fancy Note<\/code><\/p>\n<p style=\"padding-left: 60px\"><code>Publish-xSKBClient -Uri \"someone@domain.com\" -SignInAs Away -PersonalNote ([string]::Concat(\"We \" , (0x2764).ToChar($_) , \" Love PowerShell\"))<\/code><\/p>\n<p style=\"padding-left: 60px\">#endregion<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8-HSG-081916.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8-HSG-081916.png\" alt=\"Screenshot of the output that shows the presence and fancy note.\" width=\"499\" height=\"241\" class=\"alignnone size-full wp-image-79835\" \/><\/a><\/p>\n<p>Next blog post is to explain in-depth about Lync client class <a target=\"_blank\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.lync.model.lyncclient_di_3_uc_ocs14mreflyncclnt_properties.aspx\">properties<\/a>, <a target=\"_blank\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.lync.model.lyncclient_di_3_uc_ocs14mreflyncclnt_events.aspx\">events<\/a>, <a target=\"_blank\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.lync.model.lyncclient_di_3_uc_ocs14mreflyncclnt_methods.aspx\">methods<\/a> with real world examples using PowerShell.<\/p>\n<p>That is all there is to working with the Lync 2013 SDK and PowerShell for today. I can\u2019t wait to see the next post !<\/p>\n<p>I invite you to follow the Scripting Guys on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to them at <a target=\"_blank\" href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Guys Forum<\/a>. See you tomorrow.<\/p>\n<p>Until then always remember that with Great PowerShell comes Great Responsibility.<\/p>\n<p><strong>Sean Kearney<\/strong>\nHonorary Scripting Guy<\/p>\n<p>Cloud and Datacenter Management MVP<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Get started with the Lync 2013 SDK by using PowerShell to manage Skype for Business 2016 client. How do I integrate Windows PowerShell with the Lync SDK to manage Skype For Business client? MVP Chendrayan Venkatesan is back again to show us how to get started with the Lync 2013 SDK and do some [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[568,685,641],"tags":[696,56,59,45],"class_list":["post-79745","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hey-scripting-guy","category-scripting-techniques","category-windows-powershell","tag-chendrayan-venkatesan","tag-guest-blogger","tag-sharepoint","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Get started with the Lync 2013 SDK by using PowerShell to manage Skype for Business 2016 client. How do I integrate Windows PowerShell with the Lync SDK to manage Skype For Business client? MVP Chendrayan Venkatesan is back again to show us how to get started with the Lync 2013 SDK and do some [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/79745","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=79745"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/79745\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=79745"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=79745"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=79745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}