title: Turn two arrays output into a table with dynamic updating in Powershell
body: <pre><code>$array1 = @("device1", "device2", "device3")
  $array2 = @("alive", "down", "alive")
  </code></pre>
  
  <p>I want to take the two arrays and output them in table format dynamically so I can change the color of the text depending on if the host is alive or down. I can currently do this, but the drawbacks of the below method outputs everything at once, and I cannot color the lines:</p>
  
  <pre><code>$max = ($array1, $array2 | Measure-Object -Maximum -Property Count).Maximum    
  
  (0..$max | `
  Select-Object `
  @{n="Count";e={"{0,3:N0}" -f $arraycount[$_]}},`
  @{n="Device";e={$array1[$_]}},`
  @{n="Status";e={$array2[$_]}} `
  | Out-String).Trim()
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>Count Device  Status
  ----- ------  ------
    1   device1  alive
    2   device2  down
    3   device3  alive
  </code></pre>