Skip to content

New-ExchangeAddressList

Exchange: Creates a new Address List

#Requires -Version 5.1

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

    [string]$DisplayName,

    [ValidateSet('None', 'AllRecipients', 'MailboxUsers', 'Resources', 'MailContacts', 'MailGroups', 'MailUsers')]
    [string[]]$IncludedRecipients = @('AllRecipients'),

    [string]$Container
)

Process {
    try {
        $params = @{
            'Name'               = $Name
            'DisplayName'        = if ($DisplayName) { $DisplayName } else { $Name }
            'IncludedRecipients' = $IncludedRecipients
            'Confirm'            = $false
            'ErrorAction'        = 'Stop'
        }
        if ($Container) { $params.Add('Container', $Container) }

        $addressList = New-AddressList @params

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

        Write-Output $result
    }
    catch {
        throw
    }
}

Specifies the unique name of the address list.

Specifies the display name of the address list. Defaults to the Name if not specified.

Specifies the types of recipients to include in the address list. Defaults to 'AllRecipients'.

Specifies the path to the container where the address list is created.

An interactive directory of PowerShell scripts.