Set Lync LineURI based on AD IP Phone value (set-lineuri-from-ad.ps1)

I wrote this quick PowerShell script in August last year, when I needed to set several thousand Line URI attributes within Lync 2010 based on values present in AD. This script looks for IP Phone values starting with the number 1 as can be seen within the opening command. It then uses the IPPhone and Telephone attributes in AD to set a Line URI value.

This script is provided as-is, and I hope it provides you a head start if your looking to complete a similar task. You will need to customise the script to your requirements, in my case I needed 4 digit extension numbers from AD to be held within the Lync Line URI.

To test this command, you could restrict its scope by matching a specific user, eg: Get-CsAdUser -LdapFilter “IPPhone=1234”

Before I could use this I had to back-port some data from the Lync LineURI attribute, see set-adipphone-from-lineuri.ps1 for more details.

# set-lineuri-from-ad.ps1
# Sets users Lync LineURI based on the IPPhone and Telephone attributes in AD.  
# 2013-07-25 - R. Jervis (www.jervis.ws)

$RJUsers = Get-CsAdUser -LdapFilter "IPPhone=1*"

foreach ($user in $RJUsers)
    {
        echo $user.SamAccountName
        $phoneNumber = $user.Phone
        #echo "User Phone Number $phoneNumber"
        $phoneNumber = $phoneNumber -replace "[^0-9]"
        #echo "User Cleaned Number: $phoneNumber"
        $phoneNumber = $phoneNumber.substring($phoneNumber.length - 4, 4)
		#echo "User Ext Number: $phoneNumber"
		if ($phoneNumber -eq $null) { Write-Host "NULL VALUE" } else { Write-Host "ABC" }
		$phoneNumber = "tel:+" + $user.IPPhone + ";ext=" + $phoneNumber
        echo "Lync Line URI: $phoneNumber"
        Set-CsUser -Identity $user.Identity -LineUri $phoneNumber
        echo ------------------------------------
    }
(Visited 2,213 times, 1 visits today)
Facebooktwittergoogle_plusredditpinterestlinkedinmail