PowerShell script for getting member count of a Dynamc Distribution Group - Exchange/ M365 /Hybrid

Srbh_TheComputerGuy 101 Reputation points
2021-01-20T16:39:23.79+00:00

I am trying to get member count of Dynamic Distribution group. Below command works well for single DDG

$member = Get-DynamicDistributionGroup -Identity "DDGName"
Get-Recipient -RecipientPreviewFilter $members.RecipientFilter -resultsize unlimited).count

I need help with a script that can generate member count for all the DDG's in my environment (Exchange 2016 in a hybrid setup)

I have tried passing multiple DDG's in a variable however I get below

Cannot process argument transformation on parameter 'Identity'. Cannot convert the "System.Collections.ArrayList"
value of type "System.Collections.ArrayList" to type "Microsoft.Exchange.Configuration.Tasks.DynamicGroupIdParameter".

  • CategoryInfo : InvalidData: (:) [Get-DynamicDistributionGroup], ParameterBindin...mationException
  • FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-DynamicDistributionGroup
Exchange Hybrid management
0 comments No comments
{count} votes

Accepted answer
  1. KyleXu-MSFT 26,396 Reputation points
    2021-01-21T02:38:25.657+00:00

    @Srbh_TheComputerGuy

    This script below will be useful to you:

    $DDGS = Get-DynamicDistributionGroup  
      
    foreach($DDG in $DDGS){  
        $temp = $DDG.Name  
        $value = (Get-Recipient -RecipientPreviewFilter (Get-DynamicDistributionGroup $temp).RecipientFilter -resultsize unlimited | Measure-Object).count  
        Write-Host $temp" has "$value" Group Members"  
    }  
    

    Save this script into a .PS1 file, then run it in PowerShell:
    58875-qa-kyle-10-36-32.png


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.