How to create Address List by Domain suffix in Office 365

Introduction

This script will create address lists by domain suffix in Office 365 when this tenant has multiple domains.

Scenarios

This script is to help Exchange Administrators to create address lists by domain suffix in Office 365 when this tenant has multiple domains.

Script

You can use this script in the following way.

1. Open Windows PowerShell.

2. Type the one command< Script Path> at the Windows PowerShell Console.
For example, type C:\Script\
EXOCreateALByDomainSuffix.ps1

Here are some code snippets for your references.

PowerShell
Edit|Remove
$domainex = "*" + $domain.DomainName
$Nu = '$null'
$str = "(Alias -ne $Nu) -and (WindowsEmailAddress -like '$domainex')"
$Filter = [scriptblock]::Create($str)
New-AddressList -Name "$($domain.DomainName) Address List" -RecipientFilter $Filter

Examples

   Example: Create address lists by domain suffix and the address list will be named 'domain name' address list.

The sample is showed below
 
EXOCreateALByDomainSuffix.ps1 -Credential $credential

Result Screenshot:

Prerequisites

Exchange Online
Windows PowerShell 2.0
crosoft All-In-One Script Framework is an automation script sample library for IT Professionals. The key value that All-In-One Script Framework is trying to deliver is Scenario-Focused Script Samples driven by IT Pros' real-world pains and needs. The team is monitoring all TechNet forums, IT Pros' support calls to Microsoft, and script requests submitted to TechNet Script Repository. We collect frequently asked IT scenarios, and create script samples to automate the tasks and save some time for IT Pros. The team of All-In-One Script Framework sincerely hope that these customer-driven automation script samples can help our IT community in this script-centric move.