Forum Discussion
Mark Louie Diaz
Aug 29, 2018Copper Contributor
Get mailcontact if member of any group
Hi Tech Community, May I ask how can I accomplish the subject? I want to know before removing a mail contact if it is a member of a Distribution group. Best Regards, Mark
Joshua Bines
Dec 05, 2024Iron Contributor
It's funny coming across your own posts again.... I've had questions about how can this be completed for cloud only objects in Exchange Online? This should help and is much better than everything else I've seen ;) Stay safe out there! J
$allcontacts = Get-MgContact -all -Property MemberOf -ExpandProperty MemberOf
$allcontactsingroup = $allcontacts | ?{$_.memberof -ne $null}
#Print to Screen
$allcontactsingroup | FT DisplayName,MemberOf
#Export to CSV with some Funkyness (is that even a word?)
$allcontactsingroup | Select *, @{Name = 'MemberOfToString'; Expression = {$($_.MemberOf.id -join ',')}} | export-csv contactsingroup.csv