Remove All Members from Distribution Group using PowerShell

Is there a way using the "Remove-DistributionGroupMember" command to remove all members from a distribution group instead of having to type in each member?
LVL 4
advserverAsked:
Who is Participating?
 
MesthaConnect With a Mentor Commented:
I haven't tried it, but if you get the membership of the group, then pipe it, that should do it.

get-distribitutiongroupmember "groupname" | remove-distributiongroupmember groupname

I haven't tried it, so it is theoretical.

Simon.
0
 
mrmarkfuryCommented:
Have you tried this?
Remove-DistributionGroupMember -Identity "Group Name" -Member *

Open in new window

0
 
advserverAuthor Commented:
 The error I received after trying -Member *  is listed below.  Thank you for your quick response!  Any other suggestions are greatly appreciated.


Remove-DistributionGroupMember : There are multiple recipients matching the ide
ntity "*". Please specify a unique value.
At C:\Documents and Settings\--\Desktop\removedg.ps1:1 char:31
+ remove-distributiongroupmember  <<<< -identity "dg72" -member *
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
mrmarkfuryCommented:
Apparently that cmdlet only allows for the removal of a unique member. Could you instead run Remove-DistributionGroup to delete the group, and then create a new one using New-DistributionGroup?
0
 
advserverAuthor Commented:
I was trying to avoid doing that but it appears that might have to be the solution.  This command will be running on a daily basis.  I will try it out and let you know!  Once again thanks for your quick response!
0
 
advserverAuthor Commented:
Mestha,

That worked!  Do you know the proper syntax for the [-Confirm [<SwitchParameter>]] ?  I attempted [-Confirm [A]]   -Confirm [A]  and -Confirm A and all failed.  
0
 
MesthaConnect With a Mentor Commented:
You aren't confirming that you want to do it with the -confirm switch, you are saying you don't want to see the confirm prompt.

I believe it is this:

"-Confirm:$false"

Simon.
0
 
advserverAuthor Commented:
Thank you very much for your help!  That worked perfectly!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.