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.
***Caution***ย
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 )