ForeachObject to add to an array?

by BustedFlush at 2013-03-22 06:41:14

$array = @()
$proc = Gwmi Win32_Process

foreach ($pr in $proc){
$object = $pr.Caption.ToString()
$object += $array

This doesn’t work. $array stays empty.
I initialized the array before the loop, I get the expected results for $pr.
What am I missing?
by mjolinor at 2013-03-22 06:58:20
You have your operands backwards. You are adding the array to the object, not the object to the array.
by BustedFlush at 2013-03-22 07:01:48
Yerp. That was it.