ForeachObject to add to an array?

Welcome Forums General PowerShell Q&A ForeachObject to add to an array?

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years ago.

  • Author
  • #5714

    Points: 0
    Rank: Member

    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.


The topic ‘ForeachObject to add to an array?’ is closed to new replies.