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 )
Google is updating how articles are shown. Don’t miss our leading home lab and tech content, written by humans, by setting Virtualization Howto as a preferred source.
