Forum Discussion
Mark Louie Diaz
Jul 15, 2018Copper Contributor
Powershell script to get all group membership(UG or DL) and remove that user only to that group
Hi, May I ask for your assistance to edit this script from Microsoft instead of checking every group that a user is member of maybe I could use the variable $filter in removing the user also? ...
Jul 15, 2018
You can combine the two scripts as follows. Here you search the groups where the user is member and then removes the user from those groups.
$email= read-host -prompt "user@domain.com"
$Mailbox=get-Mailbox $email
$DN=$mailbox.DistinguishedName
$Filter = "Members -like ""$DN"""
Get-DistributionGroup -ResultSize Unlimited -Filter $Filter | %{Remove-DistributionGroupMember -identity $_.name -Member $email -confirm:$false}
Get-UnifiedGroup -ResultSize Unlimited -Filter $Filter | %{Remove-UnifiedGroupLinks -Identity $_.name -LinkType Members -Links $email -Confirm:$false}
Mark Louie Diaz
Jul 16, 2018Copper Contributor
Hi Nestori,
How can I export the membership first so that I have backup for evidence before we removed it?
Best Regards,
Mark Diaz
How can I export the membership first so that I have backup for evidence before we removed it?
Best Regards,
Mark Diaz