This script shows how to add address lists into all Address Book Policies.
This script is to help user to add multiple address lists to all existing Address Book Policies.
This script contains one advanced function Add-OSCEXABP, you can use this script in the following ways:
Method 1:
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.
# 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"
# 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"
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:

Exchange 2010 SP2 and above Exchange Version
PowerShell 2.0