I was preparing to speak at Microsoft Technology User Group (MTUG) here in Norway at the PowerShell Script Club. My session for the night was going to be Lync Server Management Shell. First I thought I was not going to prepare anything and wing the whole session. The more I thought about it, winging any session that I am going to give in front of an audience is seldom a good idea. So I thought, ok make a blog post instead. I will here add my favourite features, oneliners and scripts that I have found working with Lync Server. I will update this blogpost as I remember and find new features, oneliners and scripts. Please let me know of your best PowerShell tricks in Lync.

Last updated 17.01.2012

Connecting

In addition to log on the Lync Server and open Lync Server Management Shell you can also access and work with Lync through remote PowerShell which came available in V2. Here is what you need to connect. The url could be your external webservices url as well

Scripts

There are a lot of scripts that is created and expand on Lync Server PowerShell functionality and and some that simplifies working with Lync as well as monitors the solution. Below are some of my favourite scripts. Please let me know of other epic scripts out there.

A script to install prerequisites on Server 2008 R2 before you start install Lync Server on the OS. You can download the resource kit tools, Silverlitght and other tools easily. You even have som post deployment options in the script as well. This script is highly recommended and I use it in every deployment.

A scripts that read unassigned numbers and depends on you having put you entire number serie there. It will find all numbers assigned to users, devices and features in Lync and find what numbers are available in any given unassigned numbers series. This is a script that saves you the pain of managing available numbers in an excel sheet.

This script is for demo or initial deployments only. It is created for norwegian rules and genereates an easy way to dial out through one gateway and has the usual normalization rules for Norway. To edit the script and find the nomralization rules for your country see the Dialing Rule Optimizer.

This script is used in an OCS to Lync migration scenario. It will reset all policies to $Null so that they use Global or Pool level policies for External access, Voice Policy and so on. The reason for this is that all users should use what you define for Lync and not what you inherit from OCS.

Script to monitor how many concurrent calls a particular OCS or Lync Mediation Server is handling. The script grabs the counters for inboud and outbound calls, parses their values, adds them together, and dumps the output into a CSV file. A good tool to find how many concurrent calls you have on your deployment

A script to enable users to search for external contacts and Video Conferencing endpoints from Lync. It creates a contact in AD and adds the SIP address to the msRTCSIP-PrimaryUserAddress so it will be synced to the addressbook in Lync.

Scripting Tips

There is a lot of techniques used for scripting. The best script tips I know of I will list here.

Use Write-Debug

Lets you easilly define debug lines that can test variables and logic in you script that is good to use when developing the script but that not need to be there when it is used in production. When you want to debug the script you change the $DebugPreference from ‘SilentlyContinue’ to ‘Continue’. Then all Write-Debug lines will be displayed.

Use Functions

Functions are scripts in scripts. If it is certain things you need to do more than once in you script, make it a function with an input and output. I have also seen functions being used to organize your script in a better way to make it easier and more ordered to view.