Question about Large integers and the range operator in Powershell

I'm working on a script to create phone number blocks out of number ranges in Lync, and I have a requirement to use full e.164 numbers which can be up to 15 digits which are proving to be a bit of a problem.  When I pull out the start and end numbers for a given range, I get something like:

NumberRangeStart             : tel:+19995551200
NumberRangeEnd               : tel:+19995551299

I go to strip off the leading text and Powershell turns the number into an Int64 as expected:

$RangeStartInt = $Range.NumberRangeStart.TrimStart("tel:+")
$RangeEndInt = $Range.NumberRangeEnd.TrimStart("tel:+")

So my variables are now 19995551200 and 19995551299.  When I go to create the array using the range operator, I get:

PS C:\WINDOWS\system32> $RangeStartInt..$RangeEndInt
Cannot convert value "19995551200" to type "System.Int32". Error: "Value was either too large or too small for an Int32."
At line:1 char:1
+ $RangeStartInt..$RangeEndInt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastIConvertible

My question is this, does the range operator only work on Int32 objects?  Is there an alternative that might work on Int64 objects or should I just use something like an i++ to create the array manually?  Any thoughts are appreciated as it's very strange...

November 19th, 2013 10:42pm

How's it goin Dude?

I'm still looking for official documentation, but according to this article (see the '2 Restrictions and a Caveat' section), you're stuck with Int32 for the range operator.

Free Windows Admin Tool Kit Click here and download it now
November 20th, 2013 12:35am

The Dude abides of course, but man that range operator really tied the array together... I'll go ahead and i++ my way through the arrays old school then.  Thanks! :)
November 20th, 2013 2:26pm

200..299 | % {"tel:+19995551$_"}

  • Proposed as answer by Mike Laughlin Wednesday, November 20, 2013 3:07 PM
Free Windows Admin Tool Kit Click here and download it now
November 20th, 2013 2:35pm

200..299 | % {"tel:+19995551$_"}

  • Proposed as answer by Mike Laughlin Wednesday, November 20, 2013 3:07 PM
November 20th, 2013 2:35pm

The Dude abides of course, but man that range operator really tied the array together... I'll go ahead and i++ my way through the arrays old school then.  Thanks! :)

That is a perfect response, my day just got better. =]

Take a look at Dirk's suggestion though, that'll definitely do what you need.

Free Windows Admin Tool Kit Click here and download it now
November 20th, 2013 3:06pm

Had the same problem and Dirk's solution of building the ranges I needed, worked great after I struggled with the same long integer issue with my phone numbers.
May 15th, 2015 3:14pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics