ForeachObject to add to an array?

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 5 months ago.

  • Author
    Posts
  • #5714

    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.

    Thanks!!!

You must be logged in to reply to this topic.