Managing Lync Server 2013 with Windows PowerShell—Part 1

Managing Lync Server 2013 with Windows PowerShell—Part 1

  • Comments 4
  • Likes

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

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • If it's an actual group, here's a one liner I developed and talk about in my LyncFix.com blog that has worked well for me: get-adgroupmember -identity “your group” | foreach {get-aduser $_.samaccountname | foreach {enable-csuser -identity $_.userprincipalname -registrarpool yourpool.domain.com -sipaddresstype samaccountname -sipdomain domain.com}}

    You can modify it to use any PowerShell command, not just enable-csuser of course, but that's the typical example.

  • @Anthony

    Excellent! Thanks for sharing some Lync goodness with the rest of us :)

    That's a great example of how an Admin can target new Lync users in Active Directory for enablement.
    The Power of PowerShell!

    Sean


  • Because Lync Server 2013 requires PowerShell 3.0, where the latter auto loads the relevant modules (containing cmdlets run for the first time), the Import-Module statement as illustrated here is redundant.


    http://www.leedesmond.com