Do you, like me, need to migrate large swaths of PSTN numbers from your existing telephony solution to Microsoft Teams or similar? Do you have a massive list of numbers you need to plan for migration?
and let me guess, the best you can get from the carrier or the incumbent PBX vendor is a list of numbers?
I’m personally working on a more elaborate function to add to UcmPsTools, but I figured I’d throw this up here for now.
This script will run through all the numbers in “Samplenumbers.txt” and count the unique 1000 number and 100 number blocks.
Once that’s finished, it will run through each of the 100 number ranges and check to see how many numbers are used and give you a quick and nasty report via Out-Grid View
$numbers = (Get-Content -path .\samplenumbers.txt -raw) -Split([Environment]::NewLine) | Sort-Object
$groups = @()
$workingset= @()
#First, find all the unique 1000 number blocks
Write-output "finding unique 1000 number blocks"
Foreach ($number in $numbers)
{
#skip the number if its too small
If ($number.Length -ge 4)
{
$Length = ($number.length - 3)
$workingset += ($number).substring(0,$Length)
}
}
$working1000s = ($workingset | Sort-Object -Unique)
Write-output "finding unique 100 number blocks"
#Then 100 blocks
$workingset= @()
Foreach ($number in $numbers)
{
#skip the number if its too small
If ($number.Length -ge 3)
{
$Length = ($number.length - 2)
$workingset += ($number).substring(0,$Length)
}
}
$working100s = ($workingset | Sort-Object -Unique)
### Now report on the contents of each range
Write-output "finding numbers inside 100 number blocks"
ForEach ($100NR in $working100s)
{
$ThisBlock = [PSCustomObject]@{
'StartNumber' = '0'
'EndNumber' = '0'
'Count' = '0'
'numbers' = @()
}
$ThisNR = ($numbers -match "$100nr..")
$Arraytop = ($thisNR.count -1)
$ThisBlock.StartNumber = $ThisNR[0]
$ThisBlock.EndNumber = $ThisNR[$arraytop]
$ThisBlock.count = ($ThisNR.count)
$ThisBlock.numbers = $ThisNR
$groups += $ThisBlock
}
$groups | sort-object -Property "count" -Descending | Out-GridView