Today, we create a script, which allow to us set free numbers to users in Lync, which didn’t have it and add this number to ActiveDirectory user profile.
Connect to Lync server
Firstly, we create a function that connects to our lync server. It’s very similar with our Exchange function, that we have created previously.
It was the simpliest step in our script. We take our credentials and connecting to our server. If you have error such : “Access denied”, you should check that the user has remote management permissions on Lync server, and you must be sure that WinRM was activated on the Lync server.
You may also need to download Lync Server 2013 Management Pack ( in my case), you can do it here.
Determine used numbers
After successful connection, we must determine which numbers we can use in our range. To do that we will use a several “get” cmdlets. Accordingly to your environment, you can use cmdlets for other objects, but in my example, I took only those that I use at my server:
We get the list of used numbers, and now we can work with it.
We will setting our numbers to users by random. But first we should customize our list and get users without phone:
In addition, you can customize selection of objects without Phone by properties of it’s objects.
Setting the numbers
For setting numbers, we will use foreach construction and as I previously said – random :
First part has done, and we continue further.
Searching AD users
Now, we should find these users in AD and setting up the numbers, that we has given to them. In my code, I will use the “proxyAddresses” parameter to exclude “ghost users” 😀
Setting numbers to users from AD
Now, the last action. Let’s add the numbers to users in a simple way :
That wasn’t so difficult, was it? 😀 Hope it helps to you!