title: How to Export-CSV of Active Directory Objects?
body: <p>I'm trying to get a dump of all user records and their associated groups for a user ID revalidation effort. My security officer wants it in CSV format.</p>
  
  <p>This works great:</p>
  
  <pre><code>Get-ADUser -Filter * -Properties * | Select-Object -Property Name,SamAccountName,Description,EmailAddress,LastLogonDate,Manager,Title,Department,whenCreated,Enabled,Organization | Sort-Object -Property Name | ConvertTo-CSV
  </code></pre>
  
  <p>However, that does not include the groups the user is a member of.</p>
  
  <p>Attempts at something like this have failed:</p>
  
  <pre><code>Get-ADUser -Filter * -Properties * | Select-Object -Property Name,SamAccountName,Description,EmailAddress,LastLogonDate,Manager,Title,Department,whenCreated,Enabled,Organization, @{$_.MemberOf |Get-Group|ForEach-Object {$_.Name}} | Sort-Object -Property Name | ConvertTo-CSV
  </code></pre>
  
  <p>This also failed:</p>
  
  <pre><code>Get-ADUser -Filter * -Properties * | Sort-Object -Property Name | ForEach-Object {
      $_ | Format-List -Property Name,SamAccountName,Description,EmailAddress,LastLogonDate,Manager,Title,Department,whenCreated,Enabled
      $_.MemberOf | Get-ADGroup | ForEach-Object {$_.Name} | Sort-Object
  }  | ConvertTo-CSV
  </code></pre>
  
  <p>I'm probably missing something simple.
  Any help would be greatly appreciated.
  Thanks!</p>