Creating Numeric Ranges

by Feb 16, 2009

There is a clever trick in PowerShell to create numeric ranges that you probably know:

1..10

But did you know you can use variables with this trick? Try this:

$start = 100
$stop = 200
$start..$stop

Let's say you defined an array and want to return all elements except the first one. Here is a way to do it:

$array = 1..10
$array[1..$($array.length-1)]