How do I dynamically add elements to arrays in PowerShell?

前端 未结 4 1590
执念已碎
执念已碎 2021-02-12 15:10

I don\'t have much PowerShell experience yet and am trying to teach myself as I go along.

I\'m trying to make some proof of concept code for a bigger project. The main g

4条回答
  •  死守一世寂寞
    2021-02-12 15:37

    Instead of re-creating the array in each loop iteration (which is basically what's happening each time you add to it), assign the result of the the loop to a variable:

    $testArray = foreach($item in $tempArray)
    {
        addToArray $item
    }
    

提交回复
热议问题