Skip to content

Add-ExchangeDistributionGroupMember

Exchange: Adds members to a Distribution Group

#Requires -Version 5.1

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

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

    [switch]$BypassManagerCheck
)

Process {
    try {
        $results = foreach ($m in $Member) {
            try {
                $params = @{
                    'Identity'    = $Identity
                    'Member'      = $m
                    'Confirm'     = $false
                    'ErrorAction' = 'Stop'
                }
                if ($BypassManagerCheck.IsPresent) { $params.Add('BypassSecurityGroupManagerCheck', $true) }

                Add-DistributionGroupMember @params

                [PSCustomObject]@{
                    Group     = $Identity
                    Member    = $m
                    Action    = "MemberAdded"
                    Status    = "Success"
                    Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
                }
            }
            catch {
                [PSCustomObject]@{
                    Group     = $Identity
                    Member    = $m
                    Action    = "MemberAdded"
                    Status    = "Failed"
                    Error     = $_.Exception.Message
                    Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
                }
            }
        }

        Write-Output $results
    }
    catch {
        throw
    }
}

Specifies the Identity of the distribution group.

Specifies one or more identities of the members to add.

Off

If set, bypasses the security group manager check.

An interactive directory of PowerShell scripts.