3

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?

bgmCoder
  • 6,205
  • 8
  • 58
  • 105
  • Please check this link:[How to get all groups that a user is a member of?](https://stackoverflow.com/questions/5072996/how-to-get-all-groups-that-a-user-is-a-member-of) – Lina Nov 15 '18 at 06:45
  • I'm working with Office365 online; I don't think I can use Active Directory powershell. Or at least, when I do, it connects me to my local AD. – bgmCoder Nov 15 '18 at 14:30
  • Also, the examples in that thread require a username. Mail-Contacts do not have a username. – bgmCoder Nov 15 '18 at 17:47

1 Answers1

1

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.

bgmCoder
  • 6,205
  • 8
  • 58
  • 105