Dude! What’s My CSUnassignedNumber Range?

In large enterprises with 100,000 + owned phone numbers belonging to Lync/Skype For Business Server environments it’s sometimes a need to quickly determine if a specific phone number is within one of the CSUnassignedNumber Ranges.

Run the script using a “DID” parameter which should be the E.164 formatted phone number.  If you forget to prefix the + the script do it automatically.

Since some environments have thousands of these ranges, it’ll filter the ranges first by pulling on those with matching country and area codes.  The output will list the Name, start and end numbers of the range in which your input number is within.  If none are found, the output will put you in the know.

Example:

The guts:

# This script will input a E164 formatted phone number as a parameter in order to compare against the CSUnassignedNumber Ranges within your envioronment.
 # The output will provide the CSUnassignedNumber in which the DID is within the start and end range.
 # Run the .PS1 using a parameter being the phone number you're searching on. Example:
 # PS E:\Lync Team> & '.\Whats My CSUnassignedNumber Range.ps1' -DID +15558675309
 # Author: Jeff McBride www.lynclead.com
 # Date: 12/12/2016

[CmdletBinding()]
 Param(
 [string]$DID
 )

Write-Host ""
 Write-Host "============================================================================================"
 Write-Host ""
 If ($DID -notlike "+*") {
 $DID = "+" + $DID
 Write-Host "- Modifying your search number to E.164 format: $DID"
 } else {
 Write-Host "- E.164 Format search number provided: $DID"
 }

$DIDPreFilter = "\" + $DID.Substring(0,5)
 $RangesGet = Get-CSUnassignedNumber
 Write-Host "- Filtering Unassigned Number Ranges only on same country/area code: $DIDPreFilter"
 $Ranges = $RangesGet | ? {$_.NumberRangeStart -match $DIDPreFilter}

If ($Ranges -ne $NULL) {
 ForEach ($Range in $Ranges) {
 $Name = $Range.Identity
 $Start = $Range.NumberRangeStart.TrimStart("tel:")
 $End = $Range.NumberRangeEnd.TrimStart("tel:")
 If ($DID -ge $Start -and $DID -le $End) {
 Write-Host "- Number Range Identified Successfully"
 Write-Host ""
 Write-Host "CSUnassignedNumber Name: $Name"
 Write-Host "CSUnassignedNumber Start: $Start"
 Write-Host "CSUnassignedNumber End: $End"
 break
 } else {
 Write-Host "- Searching - Range area code match only: $DID not found within $Name"
 }
 }
 } Else {
 Write-Host ""
 Write-Host "There are no CSUnassignedNumber Ranges that includes $DID"
 }
 Write-Host ""
 Write-Host "============================================================================================"
 Write-Host ""

 

Leave a Reply