Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell command to hide user from exchange address lists

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?

like image 970
Vova Zaycev Avatar asked Nov 01 '11 23:11

Vova Zaycev


2 Answers

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 }
like image 85
Rob Millerd Avatar answered Oct 21 '22 00:10

Rob Millerd


You can use the following script, just replace DOMAIN with the name of your domain. When executed it will prompt you for a userlogin then hide that user's account from the address lists.

$name=Read-Host "Enter login name of user to hide"
Set-Mailbox -Identity DOMAIN\$name -HiddenFromAddressListsEnabled $true

Brian.

like image 44
Brian Avatar answered Oct 21 '22 02:10

Brian