A friend of mine recently asked for one-liners for Active Directory group membership union and intersection.
These are the one-liners which I sent him:
Group Union - users present in either of the groups (he needed a list of DNs of direct members of two groups):
(Get-QADGroupMember GroupA –Type user) + (Get-QADGroupMember GroupB –Type user) | Select-ExpandProperty DN | Sort | Select-Unique
Group Intersection – users present in both groups at the same time:
Compare-Object (Get-QADGroupMember GroupA –Type user) ` (Get-QADGroupMember GroupB –Type user) ` -ExcludeDifferent -IncludeEqual | Select-ExpandProperty InputObject
You can obviously tweak them to add indirect users (with -indirect parameter) or enabled only (-enabled), etc. – see Get-QADGroupMember help for all options.
I am pretty sure that there are multiple ways to skin these cats – so if you have better alternatives - please post these in the comments.