title: How to get a value in a foreach loop into a sum?
body: <p>I have a variable in a <code>foreach</code> loop as seen in the following snippet that calculates a user's home folder size in MB:</p>
  
  <pre><code>$TotalColItems = @()
  foreach ($user in $ListofUsers)
  {
      $colItems = (Get-ChildItem $user.HomeDirectory -Recurse |
                  Measure-Object -Property Length -Sum)
      Write-Host "`r`n Size of:" $user.HomeDirectory
      "{0:N2}" -f ($colItems.Sum / 1MB) + " MB"
      $Calculation = "{0:N2}" -f ($colItems.Sum / 1MB) + " MB"
      $TotalColItems += $colItems.Sum
      $user.HomeDirectory + " = " + $Calculation | Out-File $LogFileName -Append
      Remove-Item $user.HomeDirectory -Force -Recurse -ErrorAction SilentlyContinue
      Write-Host "`r`n Removed HomeDirectory: " $user.HomeDirectory
      Write-Host "`r`n Verifying you want to remove the user: " $user.Name -ForegroundColor Yellow -BackgroundColor Red
      Write-Host "`r`n"
      Remove-ADObject $user.DistinguishedName
      Write-Host $TotalColItems
  </code></pre>
  
  <p>But I can't seem to figure out how to get a total value of all <code>$colItems</code> that I can then calculate MB off of.</p>
  
  <p>I tried putting this in the loop:</p>
  
  <pre><code>$TotalColItems += $colItems
  </code></pre>
  
  <p>but it resets itself per loop, so it doesn't keep a running appended total.</p>
  
  <p>How can I get the <code>$colItems</code> variable per loop to append their value to a variable so that I can have a sum total of all the user directory sizes?</p>