Exchange: Hide Disabled Users from the Global Address List (GAL)

mx_microsoft_borderWhen a user leaves the company, often the Exchange mail account is deleted and the user account gets disabled .

In this way, the former employee can not access corporate data, but he still appears in the Global Address List (GAL) for internal staff. He can still be selected in the address book and is also still visible in the team calendar.

The reason for this lies in the fact that the account is still in the Active Directory and in the attribute msExchHideFromAddressLists, which contains no value. If this attribute is set to TRUE, the user disappears from the Global Address List and from certain calendar groups.

To ease the work with disabled users, you can use the following PowerShell CMDlets.

Keep track every time

Which disabled users are still showing up in the address list?

To find out which disabled users are still showing up in the GAL, you can use the following CMDlet:

Get-ADUser `
 -Filter {(enabled -eq "false") -and (msExchHideFromAddressLists -notlike "*")} `
 -SearchBase "OU=<OrganisationalUnit>,DC=<Domain>,DC=<TLD>"`
 -Properties enabled,msExchHideFromAddressLists

Which disabled users won’t be displayed anymore?

If you want to display all disabled users where the attribute is already set to TRUE – those who won’t show up in the GAL anymore – this command will help you:

Get-ADUser `
 -Filter {(enabled -eq "false") -and (msExchHideFromAddressLists -like "*")} `
 -SearchBase "OU=<OrganisationalUnit>,DC=<Domain>,DC=<TLD>"`
 -Properties enabled,msExchHideFromAddressLists

Hide single users from the address list

A single user, which username is known, you can hide with this command:

Set-ADUser <Username> -Add @{msExchHideFromAddressLists="TRUE"}

This can be helpful if you created a script to disable former users. In this case you can pass the username in a variable.

Hide disabled users automatically

To ease this task, you can create a scheduled task. In this way every disabled user, who is still showing up in the GAL, is picked and the belonging attribute msExchHideFromAdressLists is set to TRUE.

Get-ADUser `
 -Filter {(enabled -eq "false") -and (msExchHideFromAddressLists -notlike "*")} `
 -SearchBase "OU=<OrganisationalUnit>,DC=<Domain>,DC=<TLD>"`
 -Properties msExchHideFromAddressLists | `
 Set-ADUser -Add @{msExchHideFromAddressLists="TRUE"}

-xyra
http://miriamxyra.com – Miriam Wiesner

Advertisements

One comment

  1. Get-ADUser `
    -Filter {(enabled -eq “false”) -and (msExchHideFromAddressLists -notlike “*”)} `
    -SearchBase “OU=,DC=,DC=”`
    -Properties msExchHideFromAddressLists | `
    Set-ADUser -Add @{msExchHideFromAddressLists=”TRUE”}

    Is this conmand correct including the – and ‘?
    Please advise as I could do with some assistance.

    Regards

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s