Forum Discussion

svc_dstone's avatar
svc_dstone
Copper Contributor
Sep 19, 2024

How to generate report of all distribution list usage over 90 days

Hello,

 

I am looking for an Exchange online Powershell script/command to run a report for how frequently all of our distribution lists are used over a 90 day period (if there is a way to generate the report in EAC that would be great too). I have found out how to run the report for 10 days, but I cannot find a command or way to generate further in the past. Any help would be appreciated, thank you.

  • deanshepherd's avatar
    deanshepherd
    Brass Contributor

    svc_dstone 

    Here is a script i wrote, it also gets me a bit more such as the members and manged by. The colum of intrest is "last changed" it will output to c:\temp\

    hope this helps
    D

     

    # Import Exchange Online module
    Import-Module ExchangeOnlineManagement
    
    # Connect to Exchange Online
    Connect-ExchangeOnline
    
    # get the date
    $reportdate = get-date -f dd-MM-yyyy
    
    # Create an empty results table
    $results = @()
    
    # Get all distribution groups and apply to each
    Get-DistributionGroup | ForEach-Object {
        # Get its record
        $groupRecord = $_
    
        # Get its membership
        $members = Get-DistributionGroupMember -Identity $groupRecord.Name | Select-Object -ExpandProperty PrimarySmtpAddress
    
    
        # Create an object combining the record and membership
        $Object = [PSCustomObject]@{
            GroupName = $groupRecord.Name
            DisplayName = $groupRecord.DisplayName
            Hidden = $groupRecord.HiddenFromAddressListsEnabled
            CreatedDate = $groupRecord.WhenCreated
            LastChanged = $groupRecord.WhenChanged
            ManagedBy = $groupRecord.ManagedBy -join ', '
            Members = $members -join ', '
        }
        # Add the object to the results table
        $results += $Object
    } 
    # Export the results to a CSV file
    $results | Export-Csv -Path "C:\temp\DistributionGroups $reportdate.csv" -NoTypeInformation
    
    # Notification that the script has finished
    Write-Host "Script Completed. The report has been saved to C:\temp\DistributionGroups $reportdate.csv"

      

    • deanshepherd's avatar
      deanshepherd
      Brass Contributor

      Apologise, I have only ever come acrosss one way to get more than 10 days


      Go to reports in the office365 admin portal (not the exchange admin portal) and click exchange

      Here is the link
      https://admin.microsoft.com/Adminportal/Home/#/reportsUsage/MailboxUsage

       

      Click on mailbox usage, then set the report range to the past 90 days (goes up to 180 here)

      in the report filter the column maiblox type to remove users and only keep shared


      Dont ask why powershell only lets you go back 10 days 😞

Resources