To get the group membership and the groups to which members belong might require the use of recursive code. It would also require you to take into account that groups may be members of multiple groups and those groups may be members of groups you've already processes -- so you'd have to keep track of what's already been processed and avoid processing it again to avoid an endless loop.
There are many examples that use PowerShell to give you a hierarchical list of group memberships. Start by searching for "powershell group membership recurse".
I'm not sure I understand your example of the CSV though. Are user2, user4, user3, and user5 members of groupC or groupA? Is groupB a member of groupA or groupC?