问题
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?
回答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.
来源:https://stackoverflow.com/questions/53310254/how-to-get-all-groups-that-a-mail-contact-belongs-to