How to remove an Address Book Policy with Powershell for Office365/Exchange On-Line

Yesterday I was playing with address book policies in Exchange On-line. After a while I wanted to delete a Address Book Policy (ABP) which I created (in this case the ABP is called svg-abp). But when I tried to remove it with the Powershell command: “Remove-AddressBookPolicy -Identity svg-abp” I was getting the error stated that there where still users connected to the ABP.

powershell_2016-11-14_10-11-20

The next step was to identify which users where still connected to the ABP. The best Powershell command I had found was on Technet (https://technet.microsoft.com/en-us/library/hh529929(v=exchg.160).aspx): “Get-Mailbox | where $._AddressBookPolicy -eq “svg-ABP”}”. But this one will not work, there is a } at the end of the cmdlet. When you remove it, it will run:

powershell_2016-11-14_10-16-52

So unfortunately this Powershell CMDlet does not work correctly. It is not showing any mailbox connected to the ABP. You need to use “Get-Mailbox | where AddressBookPolicy -eq “SVG-ABP””

powershell_2016-11-14_11-48-47

So you now have the mailbox that is connected to the ABP SVG-ABP. But one drawback of this command is that you do not query the soft deleted users/mailboxes. If there are any users with that ABP connected, you still cannot delete the ABP. To list the soft deleted users/mailboxes where the ABP has been assigned you can use the powershell command: “Get-Mailbox -SoftDeletedMailbox | where AddressBookPolicy -eq “SVG-ABP””

powershell_2016-11-14_11-49-23

So now you know which mailbox you need to give another ABP before you can remove the ABP. You can do this with the Powershell commando “Set-Mailbox -identity info_c43c66d4b5 -AddressBookPolicy “Redcoat-ABP”:

2016-11-14_10-46-28

Now you are able to remove the ABP:

2016-11-14_10-51-18

Do not forget to also delete the Offline Address Books (OAB), Address Lists (AL) and Global Address Lists (GAL) linked to the ABP.