Use Powershell to set the hidefromaddresslist attribute on Active Directory user accounts

If you have ever had the need to set the “hidefromaddresslist” or any other attribute on Active Directory accounts, powershell is definitely your friend.  The Active Directory powershell commandlets from Quest make Powershell even more powerful and useful working with Active Directory.  Below is an example of code that one can use to set the hidefromaddresslist attribute on a list of AD accounts found in a CSV file.

This makes things much easier than having to search for AD accounts one by one and then manually set the attribute on each user account.  This script can be easily modified to set whatever attribute you are needing set by simply changing the attribute name below.


Always use extreme caution when mass altering active directory attributes using a script.  If you accidentally set something improperly, you could really damage your environment.  ALWAYS test your script in a test environment before implementing in production.

  • Download the Quest Active Roles commandlets to extend your powershell commandlets functionaility:  https://www.quest.com/powershell/activeroles-server.aspx
  • Prepare a CSV file.  Make sure in the first row of the CSV file to place “username” first, then following down the column with your usernames.
Import-Csv c:\\pathtoyourcsvfile | foreach {
    #adds the username value from the csv to a variable called $user
    $user = $_.username
    #Reads the user information for AD for each user in the csv and gets the group membership for that user
    Set-QADUser $user -ObjectAttributes @{msExchHideFromAddressLists= 'TRUE'}   

If you need to connect to a different domain other than the one your workstation is joined to, use the Connect-QADService commandlet:

Connect-QADService yourdomain.com -Credential ( Get-Credential DOMAIN\\user )




Back to top button