powershell adds a user to another user's CN group
A request has been received to grant additional permissions to an existing user in your organizations Active Directory environment. The username of this existing user is “frank0”. In additional to his current responsibilities, Frank will be taking on the responsibilities of Alan who goes by the username of “alan0”.
Note: The examples shown in this blog article are being performed on a Windows 8.1 machine that has theremote server administration tools installed. The Active Directory module is not explicitly imported in these examples since Windows 8.1 runs PowerShell version 4 and the module auto-loading feature which was first introduced in PowerShell version 3 takes care of importing the module.
First, take a look at what Active Directory groups “alan0” is a member of. These are the groups that “frank0” needs to be made a member of:
The dotted notation style of accessing the MemberOf property could also be used:
Frank is currently a member of the “Information Technology” group:
A simple one-liner can be used to add Frank as a member of each of Alan’s groups:
Use the -PassThru parameter with the previous command to receive feedback about what groups Frank is being added as a member of:
In addition to the “Information Technology” group, Frank is now a member of all the groups that Alan is a member of:
Want to add multiple users to the same groups that Alan is a member of? No problem: