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.
$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