Powershell

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

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 )

 

 

 

Subscribe to VirtualizationHowto via Email ๐Ÿ””

Enter your email address to subscribe to this blog and receive notifications of new posts by email.



Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com, and a 7-time VMware vExpert, with over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, He has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family. Also, he goes through the effort of testing and troubleshooting issues, so you don't have to.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.