Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm looking for a PS script that will automatically hide all disabled users from the GAL. I ran the below command but it didn't actually hide anything so I'm thinking I must be missing something.

get-mailbox -ResultSize unlimited | where{$_.UserAccountControl -eq "AccountDisabled, NormalAccount" -and $_.RecipientTypeDetails -eq "UserMailbox"} | Set-Mailbox -HiddenFromAddressListsEnabled $True

Thanks in advance.

share|improve this question

1 Answer 1

Try this out (haven't run it myself):

Import-Module C:\Temp\Exchange.psm1
$filter = "(&(objectCategory=person)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=2))"
$users = ([adsiSearcher]$Filter).findall()
foreach($suser in $users)
    {
    if($suser.properties.item("showInAddressBook") -ne $null) {
        get-mailbox "$($suser.properties.item("sAMAccountName"))" | ? {$_.RecipientType -eq "UserMailbox"} | set-mailbox -HiddenFromAddressListsEnabled $True
    }
}

Notes:

  • Run this in the Powershell ISE, not the Exchange Management Shell.
  • You will need to change the "Import-Module" line at the top to point to the Exchange.psm1 file on your Exchange management machine for this to work.
  • I would try just printing the user accounts that you are going to hide first to make sure it is going to affect the users you think it is before you configure their mailboxes. (Put a # before the pipe to set-mailbox to comment that part out)
share|improve this answer
    
About to head out for the day but I'll give this a try tomorrow and let you know if it does the trick. Thanks for your help! –  Windows Ninja Dec 22 '11 at 0:17
    
Beware that this will work for Disabled Users, as in: Disabled in Active Directory, not for active users with disabled mailboxes :-) –  Mathias R. Jessen Dec 28 '11 at 21:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.