How do I dynamically add elements to arrays in PowerShell?

前端 未结 4 1589
执念已碎
执念已碎 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:58

    The problem is one of scope; inside your addToArray function change the line to this:

    $script:testArray += $Item1
    

    ...to store into the array variable you are expecting.

提交回复
热议问题