Link to home
Start Free TrialLog in
Avatar of naifyboy123
naifyboy123Flag for Afghanistan

asked on

Power Shell to find empty Distribution groups

Hi

I need to find empty distribution groups in Exchange 2007.
I found the following Power shell syntax but it returns groups that contain 1 user.

Get-DistributionGroup | Where-Object { (Get-DistributionGroupMember –identity $_.Name).Count –lt 1 }

I changed it to:
Get-DistributionGroup | Where-Object { (Get-DistributionGroupMember –identity $_.Name).Count –lt 0 }

but it still returns groups with members.

Can anyone please help me by providing the correct syntax i need to report on 'empty' groups with NO members.

Also, when outputting the list, the full detail (name) of each entriy is cut off and instead '...' is shown at the end.
i assume there a limit on how many characters are shown in each column.
Please help me get the full the detail in each column.

Thanks
Avatar of Postmaster
Postmaster
Flag of Australia image

This is a good link:
http://www.howexchangeworks.com/2009/10/task-find-empty-distribution-groups-in.html

Get-DistributionGroup | Where-Object { (Get-DistributionGroupMember –identity $_.Name).Count –lt 1 }

Avatar of naifyboy123

ASKER

That syntax is exactly what i posted in my question
it doesn't work
It works for me - shows all empty lists

Try adding "|ft displayname" to the end - this will show a table with only the displayname.

You can add more fields, but may need to widen your command screen
Try this:
Get-DistributionGroup | ?{!(Get-DistributionGroupMember -Identity $_)}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Shabarinath TR
Shabarinath TR
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
none of the baove works and i dont have quest ad roles.
@Postmaster - i shows gourps with 1 member in them -

let me type that again - fingers not working today :)

none of the above works and i don't have quest ad roles.
@Postmaster - i shows groups with 1 member in them -
Are you using cut/paste from the provided scripts?

If you replace the "LessThan 1" with -LT 2   do you get lists with up to 2 members?
get-qadgroup -sizelimit 0| where-object {(get-qadgroup -identity $_.name).members.count -eq 0}

This code works very well for me. But reuqire Quest AD Roles. You could try installing it as its a freeware.

Good luck
Shaba
I installed Quest Active roles and ran your syntax. worked like a charm.
thanks
all other suggestions did not work for me.
thanks everyone for your input along the way