Set Client PIN Numbers in Lync

This script will set the Lync users client PIN numbers and then email them the extension numbers and PINs.

First you need to create a CSV file with 3 columns. They should read:

  1. Username
  2. Extension
  3. PIN

You can export the usernames and Extensions from Lync using powershell to CSV

Get-CsUser | Select SamAccountName,LineUri | Export-Csv -Path C:\Lyncusers.csv -NoTypeInformation

You will need to perform some excel wizardry to remove the DDI numbers to just display the extension

Then use an excel formula to create unique and random numbers to adhere to your PIN Policy in Lync (default is 5). Please use this link to help you http://www.listendata.com/2013/02/excel-generating-unique-random-numbers.html

Once you have your CSV formed like
Username     Extension     PIN

User1              400                35798
User2             401                 58972

Save it as a CSV called ClientPinNumbers.csv

Copy this file to your Lync Front End Server

Then Edit and Copy this powershell script and save it to the same directory as the CSV file on the Lync Front End

#Script to set users Pin Numbers and email them from Csv
Import-module lync
Import-module ActiveDirectory
$domain = Get-ADDomain 
$mailserver = "mail.domain.co.uk"
$from = "lyncserver@domain.co.uk"
$subject = "Lync Phone PIN Number"
$csv = Import-Csv -Path "clientpinNumbers.csv" -Delimiter "," 
ForEach ($user in $csv){
    try{
        $testuser = Get-csUser -Identity $user.Username -ErrorAction SilentlyContinue
        Set-CsClientPin -Identity "$($domain.NetBIOSName)\$($user.Username)" -Pin $user.Pin
        Send-MailMessage -To "$($user.Username)@$($domain.DNSRoot)" -From $from -Subject $subject -BodyAsHtml `
        "<strong>Your Lync Phone Edition PIN</strong><p>Hello $($user.Username), </p><p>Your Extension Number is: `
        $($user.Extension)</p><p>Your PIN is: $($user.PIN)</p><p>Please keep this secure and safe</p>" -SmtpServer $mailserver
    }
    catch{
        Write-Host "User is not Lync Enabled"
    }
}

Replace domain.com with your internal domain name

Run this script from Windows Powershell. The email that is sent to the user will look like this

Lync

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s