PowerShell Genie

Distribution group inventory

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Get-DistributionGroup with -ResultSize Unlimited enumerates every distribution and mail-enabled security group, and the projection keeps just the display name and primary SMTP address.

The script

1PS> Get-DistributionGroup -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 DisplayName PrimarySmtpAddress GroupType
    2 ----------- ------------------ ---------
    3 All Employees all@contoso.com Universal
    4 IT Operations it-ops@contoso.com Universal
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-DistributionGroup -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress,GroupType
    1. Stage 1Get-DistributionGroup-ResultSize
    2. Stage 2Select-ObjectPositional values or no named parameters

      How it works

      Get-DistributionGroup with -ResultSize Unlimited enumerates every distribution and mail-enabled security group, and the projection keeps just the display name and primary SMTP address.

      Adapting it

      Add GroupType and ManagedBy to the property list, because the owner field is what determines whether a group has anyone left to consult before it gets retired.

      Requirements

      ExchangeOnlineManagement module with a Connect-ExchangeOnline session.

      If the result is unexpected

      A distribution-group inventory is missing mail-enabled groups.

      The selected command and recipient-type filter may not cover every group category.

      1. Inspect a known group's recipient type and select the query that matches that type.

      Validate the result

      The report includes its intended group category and documents excluded types.

      Keep the check reliable

      Avoid presenting one group-type inventory as a directory-wide group inventory.

      Primary documentation

      PowerShell objects and pipelines documentation

      Continue
      Genie guideDistribution group inventory

      Get-DistributionGroup with -ResultSize Unlimited enumerates every distribution and mail-enabled security group, and the projection keeps just the display name and primary SMTP address.