I'm not trying to devalue the answer that @Newbie Jones provided, but I've noticed that many folks seem to either favor "one-liners" or ignore PowerShell's ability to use pipelines to simplify coding and increase clarity and resort to techniques that are necessary in other programming languages. E.g., using intermediate variables to accumulate results.
Here's the same code, by way of example, just written in a different way (it's not necessarily the most efficient, though):
# Retrieve the distinguishedName for the groups in scope, as you can query this against the memberOf attribute for the user
$groupA = (Get-ADGroup "GroupA").distinguishedName
$groupB = (Get-ADGroup "GroupB").distinguishedName
$groupC = (Get-ADGroup "GroupC").distinguishedName
# memberOf is a list of the groups the user is a member of
# Use Search base to target OU, by default this will include sub OU's
Get-ADUser -Filter * -Properties memberOf, GivenName, Surname -SearchBase "OU=Test Users,OU=x,OU=y,DC=xx,DC=yy,DC=zz" |
ForEach-Object {
$props = [ordered]@{
GivenName = $_.GivenName
Surname = $_.Surname
GroupA = If ($groupA -In $_.memberof) { "True" } else {"False"}
GroupB = If ($groupB -In $_.memberof) { "True" } else {"False"}
GroupC = If ($groupC -In $_.memberof) { "True" } else {"False"}
}
[PSCustomObject]$props
} | Export-Csv filename.csv -NoTypeInformation