Skip to content

New-ExchangeDistributionGroup

Exchange: Creates a new Distribution Group

#Requires -Version 5.1

[CmdletBinding()]
Param (
    [Parameter(Mandatory = $true)]
    [string]$Name,

    [Parameter(Mandatory = $true)]
    [string]$ManagedBy,

    [string]$Alias,

    [string]$DisplayName,

    [string]$PrimarySmtpAddress,

    [ValidateSet('Distribution', 'Security')]
    [string]$Type = 'Distribution',

    [string[]]$Members
)

Process {
    try {
        $params = @{
            'Name'               = $Name
            'ManagedBy'          = $ManagedBy
            'Type'               = $Type
            'Confirm'            = $false
            'ErrorAction'        = 'Stop'
        }
        if ($Alias) { $params.Add('Alias', $Alias) }
        if ($DisplayName) { $params.Add('DisplayName', $DisplayName) }
        if ($PrimarySmtpAddress) { $params.Add('PrimarySmtpAddress', $PrimarySmtpAddress) }
        if ($Members) { $params.Add('Members', $Members) }

        $group = New-DistributionGroup @params

        $result = [PSCustomObject]@{
            Name           = $group.Name
            DisplayName    = $group.DisplayName
            PrimarySmtpAddress = $group.PrimarySmtpAddress
            Action         = "DistributionGroupCreated"
            Status         = "Success"
            Timestamp      = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
        }

        Write-Output $result
    }
    catch {
        throw
    }
}

Specifies the unique name of the group.

Specifies the owner/manager of the group.

Specifies the Exchange alias for the group.

Specifies the display name for the group.

Specifies the primary email address for the group.

Specifies the type of group (Distribution or Security). Defaults to Distribution.

Specifies an optional array of members to add to the group upon creation.

An interactive directory of PowerShell scripts.