Exchange Management Shell

suriyaehnop used Ask the Experts™
I would like to have a cmdlet which can remove the user from distributions list which he member of.

Let say, this userA is member of distri1,distri2,distri3...etct
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
This is the script for listing the groups the user belong to 

Output of this pass it to Remove-DistributionGroupMember -Identity Groupnamefromabove  -Member 'DisplayNameofUser' or if you can pipe the output then Remove-DistributionGroupMember  -Member 'DisplayNameofUser'



Is there any cmdlet in Exchange Management Shell that can query this

You can use remove-distributiongroupmember

Remove-DistributionGroupMember -Identity "GROUPNAME" -Member "USER"
Solutions Architect
The problem in what you want is that group members are actually a group properties and not a user one so it will be more than one cmdlet

if you want it in cmdlets

$grps = Get-DistributionGroup #this will return all distribution groups
$mgrps = $grps | where { (Get-DistributionGroupMember $_ | foreach {$}) -eq "UserA"} #This will return all the groups this user is member off
$mgrps | Remove-DistributionGroupMember -Member UserA

If you prefer to have it as a script save the following as a RemoveFromAllDist.ps1

and run .\removefromalldist.ps1 "John Doe"

$u = $args[0]
foreach ($g in Get-DistributionGroup) { 
   foreach ($m in Get-DistributionGroupMember $g){
      if ($ -eq $u) {
         Remove-DistributionGroupMember $g -member $m -confirm:$false
         write-host $ " was removed from " $g

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial