Assign Active Directory Phone Numbers to Line URIs
Published May 20 2019 03:00 PM 273 Views
Occasional Visitor
First published on TECHNET on Feb 01, 2011

To see a full explanation of how these scripts work, see the article Active Directory Phone Numbers and Line URIs: Together at Last! http://blogs.technet.com/b/csps/archive/2011/02/01/howtoadphonetolineuri.aspx

Convert a Phone Number to a Line URI and Assign to User

This script converts a phone number in a format similar to the following to a Line URI and assigns the Line URI to the user:

1-(206)-555-1219

1-206-555-1219

1.206.555.1219

1(206)555-1219

$enabledUsers = Get-CsAdUser -Filter {Enabled -ne $Null}

foreach ($user in $enabledUsers)

{

$phoneNumber = $user.Phone

$phoneNumber = $phoneNumber -replace "[^0-9]"

$phonenumber = "TEL:+" + $phoneNumber

Set-CsUser -Identity $user.Identity -LineUri $phoneNumber

}

Convert an Incomplete Phone Number to a Line URI

The following script will convert a number a partial phone number to a line URI, modifying the area code based on prefix. In this script, if the extension starts with the number 5 then the area code is assumed to be 206. If the extension starts with the number 6 then the area code is 425.

$enabledUsers = Get-CsAdUser -Filter {Enabled -ne $Null}

foreach ($user in $enabledUsers)

{

$phoneNumber = $user.Phone

$phoneNumber = $phoneNumber -replace "[^0-9]"

$extension = $phoneNumber -match "^5"

if ($extension)

{

$phoneNumber = "TEL:+120655" + $phoneNumber

}

else

{

$phoneNumber = "TEL:+142556" + $phoneNumber

}

Set-CsUser -Identity $user.Identity -LineUri $phoneNumber

}

Convert a Phone Number with an Extension to a Line URI

This script will convert a phone number with an extension, in the format:

1-206-555-1111 x1219

to a valid line URI with the same extension:

TEL:+12065551111;ext=1219

The script will assign the line URI to the user with that phone number.

$enabledUsers = Get-CsAdUser -Filter {Enabled -ne $Null}

foreach ($user in $enabledUsers)

{

$phoneNumber = $user.Phone

$phoneNumber = $phoneNumber -replace "[^0-9]"

$extension = $phoneNumber -match "^5"

if ($extension)

{

$phoneNumber = "TEL:+120655" + $phoneNumber

}

else

{

$phoneNumber = "TEL:+142556" + $phoneNumber

}

Set-CsUser -Identity $user.Identity -LineUri $phoneNumber

}


Version history
Last update:
‎May 20 2019 03:00 PM
Updated by: