How To: Generate multiple phone numbers when telephony enabling users

Ever needed to generate a list of 100+ phone numbers for use with e.g. OCSAssignTelUri.wsf? I have but couldn’t be bothered with inventing a new method every time anymore, so I wrote a little ps script:

param ([string] $Series, [string] $Width, [string] $Count)
if(("-?","-help","-h") -contains $args[0]) {
    Write-Host "This script will generate phone numbers based on a number series"
    Write-Host "Example: .\generatephone.ps1 -Series +1-800-555-1299 -Width 3 -Count 10"
    exit 0
[int]$Counter = $Series.SubString($Series.Length - $Width, $Width)
$Base = $Series.Substring(0, $Series.Length - $Width)
for ($i=1; $i -le $Count; $i++) {
    [string]$strlen = $Counter
    [string]$padding = ""
        for ($x = $strlen.Length; $x -le $Width - 1; $x++) {
            $padding = "0" + $padding
    $Number = $Base + $padding + $Counter
    Write-Output $Number

The script will take your base number series, in this case +1-800-555-1299 the width of 3 which allows the script to modify the last 3 digits and finally the count of phone numbers you need.

Needless to say, there’s no error handling, so if your width goes beyond dashes you get funny results. And if you only allow editing of 2 digits with a count of 100+ – well, you do the math… :o)

Anywho, just redirect the output to a file with the standard > operator, and Bob’s your uncle. Then you just need a file full of, maybe a fun little project for my summer vacation to extract users without phone numbers…


Comments (0)

Skip to main content