title: Convert CSV to nested object back to CSV based off previous and need data in PowerShell
body: <p>First off, that title may be a little confusing, and not sure how to word it. Please edit it if you need to. </p>
  
  <p>I am tasked with getting logs from a printer, and creating a cumulative report. The printer does not have the ability to supply date ranges, so I need to factor that in. My approach is to take the CSV, and then convert it to a nested object (XML or JSON), so each user can have it's printer's properties. Then I need to turn it back to a CSV and have the different months. If a CSV could not work, maybe I can use a XML, which I could leverage in PowerShell and create some custom report in HTML.</p>
  
  <p>For example, this is what one month would look like</p>
  
  <pre><code>PrinterLog-Sep10.csv
  
  User Name  Dept. ID Color Total Black &amp; White Total Total Prints
  ---------  -------- ----------- ------------------- ------------
  Mary Smith 1002     3           3                   6           
  Kevin Hart 1006     3           2                   5           
  Jeff Davis 1004     4           0                   4           
  John Doe   1001     0           0                   0           
  Joe Dirt   1003     0           0                   0           
  Jane Jones 1005     0           0                   0           
  </code></pre>
  
  <p>I also need to factor in that additional users may be added at anytime. So the following month could be like this</p>
  
  <pre><code>PrinterLog-Oct19.csv
  
  User Name  Dept. ID Color Total Black &amp; White Total Total Prints
  ---------  -------- ----------- ------------------- ------------
  John Doe   1001     2           5                   8           
  Joe Dirt   1003     7           15                  8           
  Jeff Davis 1004     6           4                   7           
  Mary Smith 1002     6           7                   5           
  Will Smart 1007     32          12                  43          
  Jane Jones 1005     3           14                  2           
  Kevin Hart 1006     6           7                   10          
  </code></pre>
  
  <p>My approach has been using this <code>foreach</code> loop, but I cannot think of how to check for news, and keep the existing data. </p>
  
  <pre><code>foreach ($user in $canonCSV) {
      $final += @{
              $user.'User Name' = @{ 
              "B&amp;W"   = $user.'Black &amp; White Total'
              "Color" = $user.'Color Total'
              "Total" = $user.'Total Prints'
              "Dept" = $user.'Dept. ID'
          }
      }
  }
  </code></pre>
  
  <p>I was thinking maybe exporting the nested objects into a XML or JSON, but when I import it, not sure how to flatten it to a CSV. I tried using <code>Compare-Object</code> but that is not working correctly for additional users. I'm literally losing sleep over this, as I cannot think of a way to get this right. I'm sure it is something small or trivial, but everything is slipping my mind. Any help is greatly appreciated. </p>