Add objects to an array of objects in Powershell

前端 未结 1 718
既然无缘
既然无缘 2021-01-31 08:00

I have this script where I want to add an object to an array called $Target in every foreach.

foreach ($Machi         


        
1条回答
  •  囚心锁ツ
    2021-01-31 08:23

    To append to an array, just use the += operator.

    $Target += $TargetObject

    Also, you need to declare $Target = @() before your loop because otherwise, it will empty the array every loop.

    0 讨论(0)
提交回复
热议问题