Depending on the number of groups and users/contacts you want to run this against, there are two approaches to try:
- Enumerate the membership of all groups in question, store it in hashtable(s) and then compare it against each user/contact.
- Use the Get-Recipient cmdlet to get the "memberof" list for each user/contact:
Get-Recipient -Filter "Members -eq '$dn'"
where you need to provide the DistinguishedName value for the object.
Hard to tell which method will be more efficient without knowing details about your environment. Here's a ready to use script that leverages method #2, feel free to edit it to better suit your needs: https://www.michev.info/blog/post/4222/generating-a-report-of-users-group-membership-memberof-inventory-v2