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.

This works great:

Get-ADUser -Filter * -Properties * | Select-Object -Property Name,SamAccountName,Description,EmailAddress,LastLogonDate,Manager,Title,Department,whenCreated,Enabled,Organization | Sort-Object -Property Name | ConvertTo-CSV

However, that does not include the groups the user is a member of.

Attempts at something like this have failed:

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

This also failed:

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

I'm probably missing something simple. Any help would be greatly appreciated. Thanks!