Tuesday, May 26, 2015

Active Directory automation : copy users from a group to another and modify attributes

I didn't know Powershell and someone asked me to copy users from a group to another. We are talking of about 300 users.......Impossible to do it manually.
They asked also to modify (I remember this was the wrong day for me), for those users, the "Dial-in tab" in Active Directory (for Radius authentication).
After some search I found dsmod, dsget and an interesting VBScript that I've adapted to my environment.
This is what I've done :


1. copy the users

dsget group "cn=sourcegroup,cn=users,dc=mydomain,dc=local" -members | dsmod group "cn=destinationgroup,ou=users,dc=mydomain,dc=local" -addmbr

2. additionally the asked me to clean a speficic field from each single user properties

dsquery user  "ou=users,dc=mydomain,dc=local" -limit 0| dsmod user -street " "

3. at the end

Set objOU = GetObject("LDAP://dc=mydomain,dc=local")
objOU.Filter = Array("user")
For Each objUser In objOU
objUser.Put "msNPAllowDialin", True
objUser.SetInfo
Next

No complications, no tricks, only the essential.
Hope this helps.
See you soon.

8 comments: