title: Exporting Membership groups for users from input file
body: <p>I have this script that reads samaccountnames from a file and outputs the name of the user with its membership information. However, the output file only shows the last record. It seems that my code is overwriting the previous record. What am I missing? Thank you so much.</p>
  
  <pre><code>ForEach ($user in $(Get-Content -Path C:\MyScripts\UsersInput.csv)) 
  {
      $username = Get-ADUser –Identity $user -Properties * 
      Get-ADPrincipalGroupMembership $user | select $username.DisplayName, name | 
      export-csv "C:\MyScripts\UsersAndTheirADGroups.csv" -NoTypeInformation  
  }
  </code></pre>