Setting Lync 2010 PINs via PowerShell

Hi,

I am currently in the process of rolling out Lync, and wanted an easy way to mass set everyone’s PIN number. Rather than setting everyone’s PIN to a single number, I wanted part of it based on their extension number. The solution I used was writing up the below PowerShell script to use in the Lync Server Management Shell.

So, why would you do this? When you want everyone to know what the PIN format is, and not accidently log in with the wrong extension due to typing it incorrectly once (they have to type it incorrectly twice).

This is what it does:

I had to import the activedirectory module because the get-csaduser command didn’t get the results as a string, meaning I couldn’t do the substring command on it.

Then, it get the two properties of officephone (needed for the pin) and the samaccount name (same as username in lync) from the users in the specified OU.

For each of those results, it sets the officephone number from Active Directory as the $phone variable, then it sets the last 3 digits of the $phone variable as the $ext variable and sets the samaccountname as the $username.

Finally it runs the set-CSClientPin command based on the username, setting the pin to 99 and the 3 digit extension.

 

You can’t set the pin to match the extension exactly as Lync will refuse to let you. You could modify this quite easily to just have everyone’s pin as 1234.

 

import-module activedirectory
$users = get-aduser -filter * -properties officephone,samaccountname -searchbase “ou=users,dc=yourdomain,dc=com,dc=au”

foreach ($user in $users)
{
$phone = $user.officephone
$ext = $phone.substring($phone.length -3,3)
$username = $user.samaccountname
Set-CsClientPin -identity $username -pin 99$ext
}

 

Happy Lyncing!

2 thoughts on “Setting Lync 2010 PINs via PowerShell

  1. Hey. So, i’m going about the same thing – starting down this road. Our samaccountnames are in the e.g. domain\123456 format – so, I ‘m wanting to set my users to samaccountname. But, thing is – i need to figure out a way to leverage the “IsPinSet $true/$false so that I don’t reset the people who already have PIN’s set. Wish me luck….

    1. Good luck :) It should hopefully just be a case of something like this in the script, adjusted to your requirements:

      if (($IsPinSet) -eq $false)
      {
      $phone = $user.officephone
      $ext = $phone.substring($phone.length -3,3)
      $username = $user.samaccountname
      Set-CsClientPin -identity $username -pin 99$ext
      }

      Completely untested though :) Hope to hear how you go, and feel free to share your finished script!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.