title: JSON output using powershell in ForEach loop
body: <p>friends!
  Starting to work with powershell and encountered a problem.
  I need to output the values of some variables in a JSON format string in a loop.
  For this, I use the following code:</p>
  
  <pre><code>.....
      foreach ($value in $memoryLast5min)
      {
          $valueInt = [convert]::ToInt32($value, 10);   
          if ($valueInt -ge $500MB)
          {
              $index = [array]::IndexOf($memoryLast5min, $value);        
              $JSON += @{'problemUsers' = @(
                     @{
                          "userName"       = $userNames[$index]
                          "memoryLast5min" = $value
                          "readLast5min"   = $readLast5min[$index]
                          "writeLast5min"  = $writeLast5min[$index]
                      } 
                  ) 
              } | ConvertTo-JSON;
          }
      }
  .....
  return $JSON
  </code></pre>
  
  <p>In the variable $JSON I get the following result:</p>
  
  <pre><code>{
      "problemUsers":  [
                           {
                               "userName":  "User1",
                               "writeLast5min":  29,
                               "memoryLast5min":  181,
                               "readLast5min":  25
                           }
                       ]
  }{
      "problemUsers":  [
                           {
                               "userName":  "User2",
                               "writeLast5min":  80,
                               "memoryLast5min":  396,
                               "readLast5min":  74
                           }
                       ]
  }{
      "problemUsers":  [
                           {
                               "userName":  "User3",
                               "writeLast5min":  32,
                               "memoryLast5min":  169,
                               "readLast5min":  29
                           }
                       ]
  }
  </code></pre>
  
  <p>But I need this result:</p>
  
  <pre><code>{
      "problemUsers":  [
                           {
                               "userName":  "User1",
                               "writeLast5min":  29,
                               "memoryLast5min":  181,
                               "readLast5min":  25
                           },
                           {
                               "userName":  "User2",
                               "writeLast5min":  80,
                               "memoryLast5min":  396,
                               "readLast5min":  74
                           },
                           {
                               "userName":  "User3",
                               "writeLast5min":  32,
                               "memoryLast5min":  169,
                               "readLast5min":  29
                           }
                       ]
  }
  </code></pre>
  
  <p>Please, help me fix the code</p>