suppose i have the following pscutomobject array script
$pscoArray = @()
foreach($server in $Servers) {
$pscoArray += [PSCustomObject]@{
Server = $server
}
}
$iteration = 0
how do i loop through the resulting $pscoArray and add to it a new member called 'iteration' and increment that based on number of objects that already exist in the array?
i.e.
$pscoArray = $pscoArray | %{ Add-Member -MemberType NoteProperty -Name 'iteration' -Value $iteration; 'iteration' = $iteration++}
ultimate output should look like this, assuming there are 3 servers in this example
iteration Server
------ ------
1 server1
2 server2
3 server3
so iteration has to be added as a member at position 0, at the beginning of the pscustomobject, although i dont know how would i do that either
p.s. i know i can just add iteration directly in the forloop, but i need this for a different purpose.