Add Address Lists to all Address Book Policies

Introduction

This script shows how to add address lists into all Address Book Policies.

Scenarios

This script is to help user to add multiple address lists to all existing Address Book Policies.

Script

This script contains one advanced function Add-OSCEXABP, you can use this script in the following ways:

Method 1:

  1. Download the script and open the script file with Notepad or any other script     editors.
  2. Scroll down to the end of the script file, and then add     the example command which you want to run.
  3. Save the file then run the script in PowerShell.

Method 2:
      1. Run Import-Module cmdlet to import this module file.
        Import-Module filepath\AddAddressBookPolicy.psm1


Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page. 

PowerShell
Edit|Remove
# Get the specific Addresslists 
$AddresslistsToAdd = Get-AddressList | where {$_.Name -like "*$NewAddresslist"} | Select-Object Name -ExpandProperty Name 
  
# Get the AddressbookPolicies 
ForEach ($Abp in Get-AddressBookPolicy) { 
# Get the current AddressLists from AddressBookPolicy 
$AddressLists = (Get-AddressBookPolicy -Identity $Abp).Addresslists | Select-Object Name -ExpandProperty Name 
# Edit each AddressLists 
ForEach($AL in $AddressListsToAdd) { 
# Only add the AddressList if it's not exist 
    If (-not($AddressLists -contains $AL)) { $AddressLists += $AL }} 
  
# Set the new AddressList into the AddressBookPolicy 
Set-AddressBookPolicy -Identity $Abp -AddressLists $Addresslists 
Write-Host "Address List $NewAddressList is now in Address Book Policy $Abp"

Examples

Example 1: Add one Address list into all Address Book Policies.
Command: Add-OSCEXABP –NewAddresslist “ADLIST3”
Screenshot:

Example 2: Add special Address lists into all Address Book Policies.
Command: Add-OSCEXABP –NewAddresslist “ADLIST”
Screenshot:

Example 3: Add all existing Address lists into all Address Book Policies.
Command: Add-OSCEXABP –NewAddresslist “*”
Screenshot:

Prerequisite

Exchange 2010 SP2 and above Exchange Version

PowerShell 2.0