Add Exchange custom attribute based on OU or group membership?
Hi all, I need to add a custom attribute to multiple users, but not every user. Is there a powershell command I can run which gets a user list based on their OU, then pipe this info into the command to add a custom attribute? I'm ok on the command to set the custom attribute, but not sure on getting the user list. Failing that, is it possible to get a user list based on group membership? Thanks in advance. Chris
February 11th, 2010 11:29am

Hey Chris,Here is a powershell script that was posted here http://powershellscripts.blogspot.com/2007/02/list-users-from-organizational-unit-ou.html, that will pull all the users from an OU. All you need to do is add the powershell command to change the attribute you want. You will add the command between the {} in the foreach statement. If you need additional help let me know.the only line you need to change is the $Dom to add the distinguished name of your OU. $Dom = "LDAP://OU=Ou Name,DC=domain name,DC=com" $Root = New-Object DirectoryServices.DirectoryEntry $Dom # Create a selector and start searching from the Root of AD $selector = New-Object DirectoryServices.DirectorySearcher $selector.SearchRoot = $root # Filter the users with -like "CN=Person*". Note the ForEach loop $adobj= $selector.findall() | where { $_.properties.objectcategory -like "CN=Person*" } foreach ($person in $adobj) { $prop=$person.properties Write-host "First name: $($prop.givenname) Surname: $($prop.sn) User: $($prop.cn)" } Write-host "There are $($adobj.count) users in the $($root.name) domain" To get members from group user powershell you would use this command Get-Group <group name> | fl members Chris cbfive.com
Free Windows Admin Tool Kit Click here and download it now
February 11th, 2010 12:14pm

Thanks both for your help. I've tested Mike's answer and it does exactly what I want - seems so simple I'm annoyed I didn't work it out myself! Thanks again. Chris
February 12th, 2010 11:38am

Sorry to revive an old thread, but is there an easy way to do this for a group? Unfortunately the OU solution won't fit my needs.
Free Windows Admin Tool Kit Click here and download it now
June 14th, 2012 10:51pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics