Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all groups that a mail-contact belongs to?

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?

like image 683
bgmCoder Avatar asked Oct 23 '25 04:10

bgmCoder


1 Answers

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.

like image 149
bgmCoder Avatar answered Oct 26 '25 01:10

bgmCoder