Scripting Lync Unassigned Number

In a previous article I outlined why should use the Lync Unassigned Number Feature.  If you haven’t read it please do so.  The problem I have is i have very few numbers that are contiguous for a few reasons but mostly because of how Phone Numbers are divided up among the telecom’s.  Essentially, telecom’s are no longer allowed to hoard phone numbers.  If they did, we could run into the IPV4 issue we’re hitting now with IP addresses (that is, imagine if a single telecom started hoarding all phone numbers, we could run out of phone numbers to issue and thus we may run into a need to add even MORE digits to phone numbers).  To help with this, when a telecom needs more phone numbers, they all retrieve phone numbers from a central pool (at least this is what our telecom provider told us when i asked why we could not get contiguous numbers).  Enough on that topic….long story short I’m left with ~6000 phone numbers…some are contiguous some are not.  I could go through and find all the contiguous ranges in the CSV file but that could get messy and I could err when using Excel.  Instead of attempting to find all these various blocks of contiguous number I’m just going to script it in with PowerShell.

Here you go:  The below will create a unique Name for each number.  Example:  Unassigned TN1, Unassigned TN2, Unassigned TN3……until the end of your CSV file.  I had to adout ~ 6000 TN’s and it took about 40 minutes…but much better than doing it manually.

**NOTE:  The below assumes you already have an Announcement service setup.

##Unassigned TN Script
$ANOUNService = “ApplicationServer:SomePoolFQDN”
$ANOUNName = “Unassigned Number”

$TNs = Get-Content -Path “some path to a csv file”
$Tel = “tel:+1”
$TELDATAs = $null
$TELDATAs = @()

foreach ($TN in $TNS)
$TELTN = $Tel + $TN

$Count = $null
$Count = 1
$Name = “Unassigned TN”

foreach ($TELDATA in $TELDATAs)
$UNANAME = $Name + $Count

New-CsUnassignedNumber -Identity $UNANAME -NumberRangeStart $TELDATA -NumberRangeEnd $TELDATA -AnnouncementService $ANOUNService -AnnouncementName $ANOUNName -Verbose
$count = $Count + 1


Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s