Hello and thanks for posting. Let’s get some formatting on that code before we go any further.
Would you mind editing your original post and using the Preformatted Text button to turn all of your shared code in to a code block? It’s usually under the plus button at the end of the formatting toolbar.
At first glance I’m onboard with your approach, but I don’t think you need to strongly type your arrays as [PSCustomObject], in fact that might cause problems so I would just leave your array declarations as $ServerRoles = @()
You could also avoid the extra work with += by declaring your PSCustomObjects inside your array declaration
$ServerRoles = @(
[PSCustomObject]@{
Connection = 1
Code = "test"
},
[PSCustomObject]@{
Connection = 2
Code = "test2"
}
)