Powershell command to hide user from exchange address lists

Vova Zaycev picture Vova Zaycev · Nov 2, 2011 · Viewed 116.9k times · Source

I'm trying to write powershell script which hides user from exchange lists.

I was able to find following command: Set-Mailbox -Identity [user id here] -HiddenFromAddressListsEnabled $true

And it doesn't give me an error message, and when I run the command twice, I get following warning:

WARNING: The command completed successfully but no settings of '[user id here]' have been modified.

Which probably means that the command did actually work.

but when I go to Exchange Management Console, and open user profile, "hide user from exchange address lists" check box is off.

What could be the reason?

Answer

Rob Millerd picture Rob Millerd · Jul 3, 2015

I use this as a daily scheduled task to hide users disabled in AD from the Global Address List

$mailboxes = get-user | where {$_.UserAccountControl -like '*AccountDisabled*' -and $_.RecipientType -eq 'UserMailbox' } | get-mailbox  | where {$_.HiddenFromAddressListsEnabled -eq $false}

foreach ($mailbox in $mailboxes) { Set-Mailbox -HiddenFromAddressListsEnabled $true -Identity $mailbox }