title: Adding multiple text file data to a csv file with powershell into specific columns
body: <p>This my code so far:<br/></p>
  
  <pre><code># Master
  Import-Csv -Path "C:\PS\SessionData\MasterList.csv" | Select-Object "Service Unit",@{ Name='UserID';Expression = { $PSItem.'UserID'.ToLower()} } | Export-Csv C:\PS\SessionData\MasterList2Col.csv -NoTypeInformation
  # Get list of total numbers per Service Unit
  Import-Csv -Path "C:\PS\SessionData\MasterList2Col.csv" | Select-Object -ExpandProperty "Service Unit" | Group-Object | Select-Object Name,Count | Out-File "C:\PS\SessionData\countUsersByBU.txt"
  
  #Citrix
  Import-Csv -Path "C:\PS\SessionData\Session Summary 09_04_2020.csv" | Select-Object -Property @{ Name="UserID";Expression={ $PSItem."Associated User" } } -Unique | Export-Csv -Path "C:\PS\SessionData\sessionCRX.csv" -NoTypeInformation
  $citrixUsers = Import-Csv -Path "C:\PS\SessionData\sessionCRX.csv" | Select-Object -ExpandProperty UserID
  Import-Csv -Path "C:\PS\SessionData\MasterList2Col.csv" | Where-Object {$citrixUsers -contains $PSItem.UserID} | ForEach-Object {"$($PsItem.'Service Unit')" } | Out-File "C:\PS\SessionData\totalCRX.txt"
  $fileCRX = "C:\PS\SessionData\totalCRX.txt"
  Get-Content $fileCRX | Group-Object | Select-Object Name,Count | Out-File C:\PS\SessionData\countCRX.txt
  
  #VPN
  Import-Csv -Path "C:\PS\SessionData\Cisco Anyconnect users 09-04.csv" | Where-Object { $PSItem.Status -eq 'Active' } | Select-Object @{Name = 'UserID'; Expression = {($_.Name -split '\\',2)[-1] }} -Unique | Export-Csv -Path "C:\PS\SessionData\sessionVPN.csv" -NoTypeInformation
  $vpnUsers = Import-Csv -Path "C:\PS\SessionData\sessionVPN.csv" | Select-Object -ExpandProperty UserID
  Import-Csv -Path "C:\PS\SessionData\MasterList2Col.csv" | Where-Object {$vpnUsers -contains $PSItem.UserID} | ForEach-Object {"$($PsItem.'Service Unit')" } | Out-File "C:\PS\SessionData\totalVPN.txt"
  $fileVPN = "C:\PS\SessionData\totalVPN.txt"
  Get-Content $fileVPN | Group-Object | Select-Object Name,Count | Out-File C:\PS\SessionData\countVPN.txt
  
  #Create new csv file with totals
  $txtMain = "C:\PS\SessionData\countUsersByBU.txt"
  $txtCRX = "C:\PS\SessionData\countCRX.txt"
  $txtVPN = "C:\PS\SessionData\countVPN.txt"
  
  #End result new.csv 
  #Get-Content ??? | Export-Csv -Path "C:\PS\SessionData\new.csv"
  </code></pre>
  
  <p>I have three text files, which has a "Name" column and a "Count" column, example below:</p>
  
  <pre><code>$txtMain = "C:\PS\SessionData\countUsersByBU.txt"
  </code></pre>
  
  <pre>
  Name    Count
  ----    -----
  HR       20
  Account  25
  Dev      25
  Sales    25
  Garden   10
  </pre>
  
  <pre><code>$txtCRX = "C:\PS\SessionData\countCRX.txt"
  </code></pre>
  
  <pre>
  Name    Count
  ----    -----
  HR         3
  Account    6
  Dev        9
  Garden     7
  </pre>
  
  <pre><code>$txtVPN = "C:\PS\SessionData\countVPN.txt"
  </code></pre>
  
  <pre>
  Name    Count
  ----    -----
  HR         7
  Account    8
  Dev        1
  Sales      5
  </pre>
  
  <p>I need to get this data into a new.csv file. Where the txtMain data has all Name columns and a total count column.
  The data from txtOne, needs to check the new.csv file for the Name column and put the Count value into a third column.
  The data from txtTwo, needs to check the new.csv file for the Name column and put the Count value into a fourth column.
  e.g. new.csv</p>
  
  <pre>
  Name   (txtMain)   (txtCRX)   (txtVPN)   (Percentage)
  ----   ---------   --------   --------   ------------
  HR          20          3         7          50%
  Account     25          7         8          60%         
  Dev         25          9         1          40%
  Sales       25                    5          20%
  Garden      10          7                    70%
  </pre>
  
  <p>Then a final column which is a calculated expression, which calculates the percentage of txtCRX and txtVPN columns from the txtMain column.<br/>
  Apologies for the noob question, haven't worked with Powershell for a while and not sure how to write the final Get and Export statement to create the new.csv file.</p>