title: PowerShell create array from ForEach and pipe into email body
body: <p>I am looping through a list of computers and checking disc space.  I want to format this information into an array that I can add as the email body.  I want the entire output into one email, I know how to send an individual email of each one.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>$ComputerList = IMPORT-CSV listofcomputers.txt
  $tableFragment = ForEach ($Computer in $ComputerList){
  $Name = $Computer.Name
  $disk = Get-WmiObject Win32_LogicalDisk -ComputerName $Name -Filter "DeviceID='C:'" | Select-Object Size,FreeSpace
  $b = ($disk.Size / 1073741824)
  $a = ($disk.FreeSpace / 1073741824)
  $a = "{0:N1}" -f $a
  $b = "{0:N1}" -f $b
  if($disk.FreeSpace -lt 10737418240){Write-Host Disk space on $Name is LOW.  Only $a GB remaining. -foregroundcolor "magenta"}
  else{Write-Host Free disc space on $Name is $a GB, out of $b GB.}
  }
  </code></pre>