Quick Fix: Office 365 DirSync Hide a user from Global Address List
November 20, 2015 14 Comments
This week i have been working on some process automation, around a user leaving an organisation using Office 365.
DirSync (and it’s newer iterations) has been a very useful for Password Sync and User creation, however it can be a bit of a drag when it comes to editing mailbox settings. In this case, Hiding a user from the Global Address List.
So to hide the Mailbox from our Office 365 Address List we need to use ADSIEdit and change the msExchHideFromAddressLists attribute to True, then wait for DirSync to do it’s thing.
This is fine for a one off, well maybe it is, but i like to script things so i can execute a bunch of actions to an account at once.
Unfortunately this attribute is not exposed to Set-ADUser, only to Get-ADUser, and Set-Mailbox is not valid here as the user has no On Prem mailbox anymore. We need a way to expose the attribute we want to edit, and save it.
We can do something like this:
$user = Get-ADUser dfunk –properties *
This tells PowerShell to collect every attribute the user has and store them as $user.
Next, we edit the attribute.
$user.msExchHideFromAddressLists = “True”
This then sets that attribute to True.
Now we save,
Set-ADUser –instance $user
This of course applies to any attribute you care to edit, i also use it when i need to add additional email addresses to an account that is provisioned via DirSync.
For even more fun why not roll this into a ‘Leavers’ script that removes their Office 365 Licenses, forwards email to other users disables there account etc etc.