none
Getting Distribution list Count RRS feed

  • Question

  • I'm looking for a PowerShell script to get a member count of all the distribution lists. I found this script from an old post but it does not seem to work on the lasted Office 365 environment

    Get-DistributionGroup -Identity DL-ATD* | Select-Object DisplayName > DL.txt

    $data = @()
    $dls = get-content DL.txt

    foreach ($dl in $dls) {


     $data += New-Object -TypeName PSObject -Property @{
      DisplayName = $dl
      Count = (Get-DistributionGroupMember -Identity  $dl  | Measure-Object).Count
     }
    }

    $data | Export-Csv -Path mydllist.csv -NoTypeInformation

    It looks like this in excel

    DisplayName       Count
    list1 0
    list2 0

    Monday, July 24, 2017 9:04 PM

Answers

  • Try this:

    Get-DistributionGroup | select DisplayName,PrimarySmtpAddress,@{n="MemberCount";e={(Get-DistributionGroupMember $_.PrimarySmtpAddress | measure).Count}}

    • Marked as answer by Sam240 Tuesday, July 25, 2017 2:27 PM
    Tuesday, July 25, 2017 6:08 AM

All replies