Goal:
-----
I want to create x number of groups. These groups will have a list of
servers. I split these servers in groups by name. What I would like is for
this function to be dynamic. I hope the example will make my goal clear.
Example:
---------
This is a very simple example... I am looking at creating 40+ groups... it
gets to be ALOT of duplicate code.
# This is what works now
Function Create-Groups {
param([system.array]$servers)
# this is where I would like to be more dynamic
$list1 = @()
$list2 = @()
$list3 = @()
$list4 = @()
$list5 = @()
foreach($server in $servers) {
if ($Server -match ".*ver1.$") {$list1 += $server}
elseif($Server -match ".*ver2.$") {$list2 += $server}
elseif($Server -match ".*ver3.$") {$list3 += $server}
elseif($Server -match ".*ver4.$") {$list4 += $server}
elseif($Server -match ".*ver5.$") {$list5 += $server}
}
# This is where I would like to be more dynamic
$global:group1 = $list1
$global:group2 = $list2
$global:group3 = $list3
$global:group4 = $list4
$global:group5 = $list5
}
Problem:
---------
Now if I wanted to make 10 groups instead of 5... I have create 5 more
arrays and global variables. I would like to do something like:
# this of course fails... is there a way I can do this?
$i = 1
while($i -lt 21) {
$list$i = @()
++$i
}



