I am attempting to use multiple arrays to pass multiple server names, and maybe other elements, that maybe be needed in conjunction to each other to a function's set of Parameters in a Powershell function. While using a single loop, if that is even possible.
I wanted to script this process so you could pass an array via a parameter as a larger function to the 2nd function but use arrays. Instead of nested Hashtable.
This is similar to what i was attempting to do but I cant seem to get the arrays to pass each element one at a time for each respective array.
This is what I have gotten to get a "similar" result but I will not work if I have to have the index position via the [0].
$servers1 = @('serv1-01','serv1-02')
$servers2 = @('serv2-01','serv2-02')
$collectionItems = @()
$temp = New-Object System.Object
$temp | Add-Member -MemberType NoteProperty -Name "Server1" -Value $servers1
$temp | Add-Member -MemberType NoteProperty -Name "Server2" -Value $servers2
$collectionItems += $temp
Write-Host "Server1 is $($item.Server1[0]) and Server2 is $($item.Server2[0])"
foreach ($item in $collectionItems)
{
Write-Host "Server1 is $($item.Server1) and Server2 is $($item.Server2)"
}
#### This is the output if you run the above script#####
Server1 is serv1-01 and Server2 is serv2-01
Server1 is serv1-01 serv1-02 and Server2 is serv2-01 serv2-02
Below is kind of the skeleton of what i am trying to accomplish... I know that you can have a nested Hashtable that uses one of the Key:Value pairs as an array, but im not sure if you can pass that in at the commandline as a nested Hashtable or how that would work to use the params to add to the nested sections of the Hashtable vs keeping this hashtable up to date ((Which would not be ideal))
I know the code below will not work but its the best visual representation of my desired end goal
function Bigger-ServerListAdding {
#List of servers to add some config too
$servers1 = @('serv1-01','serv1-02')
$servers2 = @('serv2-01','serv2-02')
#This variable can be passed in and fixed with a -join ',' as a comma separated list
$componentlist = @('sister','brother','uncle','mom','dad')
###This section should do each element not the entire array list being passed###
foreach (item in $somecollection){
Set-TheseServersOnaConfig -Server1 $item.servers1 -Server2 $item.servers2 -ComponentList $($componentlist -join ",")
}
}
Mind you this is like he 2nd question i've ever asked on StackOverflow. Any suggestions as this type of thing in the future.
Thank you very much!
-parameter {"key": "value"}