Pages

Search This Blog

Saturday, March 17, 2012

Useful commands for Active Directory Groups management

With command line tools a lot of complex tasks can be accomplished easily and efficiently; I'll state below two of common tasks that admins may need to perform in Active Directory and explain how to perform those tasks in the easiest way.


Tasks :
  1. Copy group's membership from one user to another one
  2. Copy all members from one group to another group
To show you to perform these tasks ,I'll set two scenarios - one for each task - and demonstrate how to accomplish each of them . our scenarios are:
  1. TestUser1 is a domain user who is member of two groups [ TestGroup1 & TestGroup2 ] . We require that TestUser2 - a newly created domain user - to be a member of all Active Directory groups that TestUser1 is member in it.
  2. TestGroup3 includes the following members [ TestUser3 : TestUser7 ] ,those users are required to be added to another group named TestGroup4.
Here is a screen shoot indicating that all objects [ TestUsers & TestGroups ] are located at TestOU.




For the first scenario [ task ] , it can be accomplished using Directory Services commands as follow:


dsget user "SourceUserDN" –memberof | dsmod group –addmbr "TargetUserDN"

For my example and as both users are located at TestOU which located directly under my domain node, our command will be as follow:


dsget user "CN=TestUser1,OU=TestOU,DC=itguydiaries,DC=net" -memberof | dsmod group -addmbr "CN=TestUser2,OU=TestOU,DC=itguydiaries,DC=net"

Here is a screen shoot for command execution and result :



The dsmod failure above is due to that the user is already a member of  "Domain Users" group.

For the first scenario [ task ] , we can accomplish it using Directory Service commands as follow:


dsget group "SourceGroupDN" –members | dsmod group "TargetGroupDN" –addmbr

For my example and as both groups are located at TestOU which located directly under my domain node, our command will be as follow:


dsget group "CN=TestGroup3, OU=TestOU,DC=itguydiaries,DC=net " –members | dsmod group "CN=TestGroup4, OU=TestOU,DC=itguydiaries,DC=net" –addmbr

And here is a screen shoot for command execution and result :





Hope that those commands are helpful ;)

No comments:

Post a Comment