title: Manipulating CSV Formatting for HBSS Modules
body: <p>I need help with manipulating data that I export to a CSV. Right now I actually learned how to merge columns together so that once it is put into a CSV the hostname shows on only 1 line and the other two columns I merge together so that each line will only have one hostname. I however need to take it a step further.</p>
  <p>Below is my progression:</p>
  <h1>Phase 1:</h1>
  <p>This was only good because the script retrieved the data, but as you can see below <code>Hostname1</code> shows up on every line for each caption and version, which would lead to several repeats of a machine name for several lines making the CSV file extremely longer than it necessarily should be.</p>
  <p>Script:</p>
  <pre><code>GWMI -Class Win32_Product -Comp (GC D:\McAfeeHost.txt) |
      Where {$_.Vendor -like &quot;mcafee*&quot; -or $_.Vendor -like &quot;usaf*&quot;} |
      Select PSComputerName, Caption, Version |
      Export-Csv -NoTypeInformation d:\Get-HBSSModules-Test.csv
  </code></pre>
  <p>Output in CSV:</p>
  <pre>
  PSComputerName  caption                             version
  Hostname1      McAfee Host Intrusion Prevention     8.00.0801
  Hostname1      McAfee Policy Auditor Agent          6.2.0
  Hostname1      McAfee DLP Endpoint                  10.0.260.42
  Hostname1      McAfee VirusScan Enterprise          8.8.08000
  Hostname1      ACCM                                 3.0.4.1
  Hostname1      McAfee Agent                         5.00.4006
  </pre>
  <h1>Phase 2:</h1>
  <p>I have progressed by merging the caption and version together, so that each hostname that is fetched from <code>-Comp (GC D:\McAfeeHost.txt)</code> shows up only once per line. While this is more of what I am looking for, it isn't the best option for formatting as shown below the in the output of the CSV.</p>
  <p>Script:</p>
  <pre><code>GWMI -Class Win32_Product -Comp (GC D:\McAfeeHost.txt) |
      Where {$_.Vendor -like &quot;mcafee*&quot; -or $_.Vendor -like &quot;usaf*&quot;} |
      Select PSComputername, Caption, Version |
      Sort-Object Caption |
      Export-Csv -NoTypeInformation d:\Get-HBSSModules-Test.csv
  
  $a = Import-Csv d:\Get-HBSSModules-Test.csv
  $a | Group-Object PSComputerName |
      Select-Object @{name=&quot;PSComputerName&quot;;expression={$_.Name}},
          @{name=&quot;caption, version&quot;;expression={($_.Group | % { $_.Caption, $_.Version }) -join ';'}} |
      Export-Csv d:\Get-HBSSModules-Test.csv -NoTypeInformation
  </code></pre>
  <p>Output to CSV:</p>
  <p><a href="https://i.stack.imgur.com/0YinV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0YinV.png" alt="Phase 2 Output" /></a></p>
  <h1>Phase 3:</h1>
  <p>If at all possible I would like to take each caption along with its version and put them together like phase 2, but separated by columns and still only having one hostname per line as shown below:</p>
  <p><a href="https://i.stack.imgur.com/ySZG7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ySZG7.png" alt="Phase 3 Output" /></a></p>