Managing Lync Server 2013 with Windows PowerShell—Part 1

Doctor Scripto

Summary: Use Windows PowerShell to enable Active Directory users for Lync.

Hey, Scripting Guy! Question Hey, Scripting Guy! We just spun up our Lync server, and I need to know a very easy way to enable groups of users. I have over 10,000 records to enable and not quite enough coffee to click the mouse button all that fast!

—LN

Hey, Scripting Guy! Answer Hello LN,

Honorary Scripting Guy, Sean Kearney, is here to show you a way to get all those users enabled without burning out the left mouse button!

If you're new to managing Lync Server 2013, your first experience probably has been your visit to the Lync Server Control Panel.

Image of menu

You found it well enough organized to click the option "Enable users for Lync Server." It brought up this ever so lovely console:

Image of menu

Enabling a user or two isn't quite so difficult. But how about enabling a whole slew of them? For that, we can turn to our good friend Windows PowerShell.

To access the Lync PowerShell cmdlets, you need only launch Lync Server Management Shell. But if you prefer, you can run the cmdlets from an ordinary Windows PowerShell console. Simply launch this line in Windows PowerShell on the Lync Server:

IMPORT-MODULE Lync

At this point, you are in the wonderful world of Windows PowerShell and Lync. Now we can create a user with this cmdlet:

ENABLE-CSADUser

With this cmdlet you can take all the values you would normally key into the GUI and drop them into a repeatable line.  For example, Mr. Dent would be enabled in the following manner:

ENABLE-CSAduser –identity 'Arthur Dent' –RegistrarPool 'eot-lync.contoso.local' –sipaddresstype FirstnameLastname –sipdomain contoso.local

With that, Mr. Dent (who remembered to bring his towel, of course) can now happily hop into Lync and chat about with…well…nobody.

He was, after all, our first user. If this is a scenario in which I am going to enable many users (or maybe 10,000 users—in which case, it would be "Many, many, many users," as they said in Policy Academy), we would do things differently.

First, the simplest action of them all would be to target an organizational unit in Active Directory. Let's pick on the HitchHiker's organizational unit today. Everybody in that organizational unit will become Lync enabled. Use the Get-AdUser cmdlet as you normally would to get the users:

GET-Aduser –filter * -searchbase 'OU=GuideToGalaxy,OU=Hitchhikers,DC=Contoso,DC=local'

We can now pipe in that list directly to the Enable CS-ADuser cmdlet…

Or can we?

It turns out that this particular cmdlet is geared towards one user at a time, and it will only accept single elements, not an array. So we'll have to split up the data with a Foreach statement like so:

GET-Aduser –filter * -searchbase 'OU=GuideToGalaxy,OU=Hitchhikers,DC=Contoso,DC=local' | Foreach { ENABLE-CSAduser –identity $_.Name –RegistrarPool 'eot-lync.contoso.local' –sipaddresstype FirstnameLastname –sipdomain contoso.local }

I found the cmdlet was actually pretty user-friendly. When I was trying to figure out the different SipAddressType values, I used Tab-Complete to scroll through the potential values. Or you can simply put in a bad value, such as Towel, and watch the lovely red error message pop up with the correct potential values listed on the screen!

Enable-CsUser : Cannot bind parameter 'SipAddressType'. Cannot convert value "towel" to type

"Microsoft.Rtc.Management.AD.Cmdlets.AddressType". Error: "Unable to match the identifier name towel to a valid

enumerator name. Specify one of the following enumerator names and try again: FirstLastName, EmailAddress,

UserPrincipalName, SAMAccountName, None"

I thought that was pretty nice!

So you can be as creative as you like with enabling users, targeting groups, or simply using a CSV file, if you like. I found that after I had initially enabled staff in Lync, I was using the one-line command to enable them in my onboarding script as I created them in Active Directory.

But we all do it a little differently.

Pop back in tomorrow as we check out even more Lync cmdlets!

I invite you to follow The Scripting Guys on Twitter and Facebook. If you have any questions, send an email to The Scripting Guys at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then remember to eat your cmdlets each and every day with a dash of creativity.

Sean Kearney, Windows PowerShell MVP and Honorary Scripting Guy

0 comments

Discussion is closed.

Feedback usabilla icon