This code will find all groups to which a particular email account or mail-user account belongs.
get-group | where-object -FilterScript {$_.Members -contains $user}
However, in O365 you can have mail-contacts who are not users - they are used just for mailing lists; they don't have a windowsliveid, so they won't be found in $_.Members.
How can I find all groups that a particular mail-contact belongs to?
Well, likeafoxx over in reddit came up with a solution.
$contact = Get-Contact -Identity "<Contact's Name>"
Get-Group | Where-Object {$_.Members -contains $contact}
Apparently, if you catch the get-contact value into a variable, then get-group's $_.members can search for that. I was putting the string value for the name there, but that always turned up empty. This works like a charm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With