Turning Lists of Numbers Into Useful Lists

by Nov 5, 2015

PowerShell features the ".." operator which produces lists of numbers. With the -join operator, you can convert these to almost anything you want, like comma-separated values.

And when you convert the numbers to characters, you can turn ASCII codes into letters, too.

Pipe them into ForeEach-Object, and you can take it even further and turn letters into drives.

Or use the -f operator to create server lists. Here are the examples:

#requires -Version 1


1..10 -join ','

[Char[]][Byte[]](65..90) -join ','

([Char[]][Byte[]](65..90) | ForEach-Object { $_ + ':\' })  -join ','

1..10 | ForEach-Object { 'Server{0:0000}' -f $_ }

Twitter This Tip! ReTweet this Tip!