Skip to content

Instantly share code, notes, and snippets.

@JohnLBevan
Created September 8, 2014 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnLBevan/5ad854cc52e2fa8eaee1 to your computer and use it in GitHub Desktop.
Save JohnLBevan/5ad854cc52e2fa8eaee1 to your computer and use it in GitHub Desktop.
Populate an array of similarly named servers with minimal effort.
#
# Populate a list of servers where the only thing to change between servers is the number:
#
$servers = 1..10 | %{"ccioaxpi{0:00}edc" -f $_} `
+ 1..2 | %{"ccioaxpf{0:00}edc" -f $_}
#This is the equivelant to:
#$servers = 'ccioaxpi01edc','ccioaxpi02edc','ccioaxpi03edc','ccioaxpi04edc','ccioaxpi05edc','ccioaxpi06edc','ccioaxpi07edc','ccioaxpi08edc','ccioaxpi09edc','ccioaxpi10edc','ccioaxpf01edc','ccioaxpf02edc'
#Explanation
# 1..10: creates a list of numbers from 1 to 10
# | %{}: shorthand foreach over the preceding list
# "ccioaxpi{0:00}edc" -f $_: string.Format where {0:00} says argument 0 formatted as 00, taking value from $_ (current item in foreach)
# `: code continues on next line
# +: join the following result/array to the preceding array
# everything else is same as above, only with different values
$servers | %{$_} #output contents of array to console to show what the above acheived.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment