Office365 create Global Address List
We see it’s common to use Office365 in combination with the Active Directory synchronization tool. Even when you have more AD Domains it is possible to sync them to one Azure Active Directory tenant. When you use more AD domains you sometimes want to split the Office365 mail users in different groups and give them an own address list.
Use PowerShell in Office365 Exchange Online
To login on the Exchange online with Powershell use the following commands, use your Office365 admin account;
# Get User Credentials $UserCredential = Get-Credential # Create PowerShell session $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection #Import Session Import-PSSession $Session
Create Global Address List
To create an new Address list in Office365 we are gone use PowerShell, make sure you have created the session descriptor in previous chapter.
# Create SampleA domain GAL New-GlobalAddressList -Name GAL_SampleA -RecipientFilter {((RecipientType -eq "UserMailbox") -and (UserPrincipalName -like "*@samplea.onmicrosoft.com"))} # Create SampleB domain GAL New-GlobalAddressList -Name GAL_SampleA -RecipientFilter {((RecipientType -eq "UserMailbox") -and (UserPrincipalName -like "*@sampleb.onmicrosoft.com"))}
In the Recipient Filter you can use different field to filter on, you can find them all on the Microsoft Technet site here.
Create Address List and Offline Address Book
Before we can make any Address Book Policy to the users we need to have defined an Offline Address Book. The OAB is build out an Address List that needs to be created also.
# Create Address List for SampleA domain New-AddressList -Name AL_SampleA -RecipientFilter {((RecipientType -eq "UserMailbox") -and (UserPrincipalName -like "*@samplea.onmicrosoft.com"))} # Create Offline Address Book for SampleA domain New-OfflineAddressBook -Name OAB_SampleA -AddressLists AL_SampleA # Create Address List for SampleB domain New-AddressList -Name AL_SampleB -RecipientFilter {((RecipientType -eq "UserMailbox") -and (UserPrincipalName -like "*@sampleb.onmicrosoft.com"))} # Create Offline Address Book for SampleB domain New-OfflineAddressBook -Name OAB_SampleB -AddressLists AL_SampleB
With this PowerShell command we have created the Offline Address Book and Address List for both domains. Now we can assign them to the users.
Assign Global Address List to users
Now we have created the new Global Address Lists we need to create an new Address Book Policy to assign them to our mailbox users.
# Create Address Book Policy for domain SampleA New-AddressBookPolicy -Name "ABP_SampleA” -AddressLists "" -RoomList "\All Rooms" -OfflineAddressBook “\OAB_SampleA” -GlobalAddressList “\GAL_SampleA” # Create Address Book Policy for domain SampleB New-AddressBookPolicy -Name "ABP_SampleB” -AddressLists "" -RoomList "\All Rooms" -OfflineAddressBook “\OAB_SampleB” -GlobalAddressList “\GAL_SampleB”
To assign the mailbox user this new policy use the following commands. Edit the command to your own need to specify the right user(s).
Set-Mailbox -Identity testuser@samplea.onmicrosoft.com -AddressBookPolicy "ABP_SampleA"
The Magic off filling the GAL
All the new address books are added and we have assigned them to our test user. You will see our test user has an empty address book , huh? To fill our new Global Address List and Address List we need to ‘change’ each user that needs to be in the address book. I have made an small script to do this;
$mailboxusers = Get-Mailbox -All $i=0 $count = $mailboxusers.count Write-Host "Mailboxes found: " $count foreach($mailbox in $mailboxusers){ $i++ Set-Mailbox $mailbox.alias -SimpleDisplayName $mailbox.SimpleDisplayName -WarningAction silentlyContinue Write-Output "Mailbox $i from $count changed: $mailbox.UserPrincipalName" }
With this script actually nothing get changed on the mailbox user, it just touch them so the user appears in the Address Lists. Now open the test user mailbox again and check the Global Address List, it will be filled with the users we just touched.
I found an more advanced script to touch users mailboxes at Microsoft here: link