Find Empty Distribution Groups and Email Results if they are empty - powershell

I have searched and searched and have only found 1 script online that I can't get to work correctly.  I need a powershell script that will find empty distribution groups and email the name of the empty distribution groups.

I only want the email to be sent if it finds a distribution group that is empty.

Wes FieldsAsked:
Who is Participating?
Adam BrownConnect With a Mentor Sr Solutions ArchitectCommented:
$groups = get-distributiongroup 
foreach ($group in $groups)
$members = get-distributiongroupmember $
if ($members -like $null) {send-mailmessage -to <emailaddress> -from <fromaddress> -smtpserver <servername> -subject "a group has no members" -body "$ has no members in it"}

Open in new window

That should do it.
Wes FieldsAuthor Commented:
Just tested it on my exchange server and it works just as I asked.  Thank you so much!  I am still learning how to script with powershell but you have saved me tons of time.

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.