Add user(s) to group(s) – GUI

I needed a script to add multiple users to multiple groups. It is a task I needed to do several times and will need to do this many more times in the future as well. So I decided to create a nice little script (with GUI) to help me and my colleagues with executing this task.

I also needed it to be able to to create a group if it doesn’t exist yet. So I added this feature as well. The script creates this group in a pre-defined OU, but if you want this to be variable as well, I reckon you’ll be able to change the script accordingly.

When you edit the script, in the top few lines of the script, you’d need to edit the lines given here in red, to match your environment:

Start-Transcript E:\scripts\AddMultipleUsersToMultipleGroups.txt -Append
$DefaultUserSearchBase = "OU=Users,DC=domain,DC=local"
$DefaultGroupSearchBase = "OU=Groups,DC=domain,DC=local"
$DefaultOU = "Business"

If you start the script, it’ll show this main window, which looks like this:

Screenshot of main window of the script
  1. Search field for users (SamAccountName). No need to enter wildcards.
  2. Dropdown box for sub-OU’s from the DefaultUserSearchBase variable. It will show the OU from the $DefaultOU variable when starting.
  3. List of users from the OU (as selected in 2), here you can select users (see also 4 and 6)
  4. Add button to add users to “Selected users” (6) list.
  5. Remove button, to remove selected user from “Selected users” (6) list.
  6. Selected users listbox. If no users are selected here, the script will use the selection in box 3.
  7. Search/filter field for groups. No need to enter wildcards.
  8. List of groups to add users to. The filter field (7) can be used to search for wanted groups.
  9. OK button. The script will apply the selection of users (6, if none there, then selection in 3) and add them to the selected group(s) (8). The GUI will close afterwards.
  10. Cancel button. The GUI will close and won’t do anything with the currently selected items.
  11. New group button. A pop-up will appear, where a group name can be entered. Default in the script it’ll create a Global Security group (see below in you want to change this behavior) in the OU as entered as $DefaultGroupSearchBase (see above image)
  12. Add users to group(s) button. The script will apply the selection of users (6, if none there, then selection in 3) and add them to the selected group(s) (8). The GUI will stay open but will reset the selection. This is used if you want to add more user(s) to group(s).

If you don’t want the tool to create a Global Secuirty group, go to line 107 in the script. Here you can change the type of group you’d want to create:
New-ADGroup -Name "$GroupName" -SamAccountName "$GroupName" -DisplayName "$GroupName" -GroupCategory Security -GroupScope Global -Path $DefaultGroupsOU

I’ve used some techniques, to make using this GUI/script easier:

  • In case you click the “New group” (11) button, the text box will automatically be selected, so you can start typing. You can either press OK, or use the enter key, to create the group.
  • The listboxes (3 and 8) are multi-select listboxes, so either with CTRL or Shift you’ll be able to select more than 1 item.
  • In case all the users you need to add to group(s) are in listbox 3, you don’t need to add them to the “selected users” listbox, but can just select the users and the groups and either use the OK (9) button or the “Add users to group(s)” (12) to add the selected users to the selected group(s).
  • I’ve added the Start-Transcript -append in the beginning of the script, so there will be logging, which can be used for auditing purposes (who did what).

To download the entire script, click here.

If you like this script and want to support me so I can create and share more scripts, please consider donating to me through PayPal.

4 thoughts on “Add user(s) to group(s) – GUI

  1. Great script! Works like a cham! If there was someway to have that Selected Users box be used in conjuction with the groups, how would you go about doing so?


  2. Amazing script! Thanks

    Is there a way to multiselect the groups by a checkmarkbox
    for example if we have a user that is in Sales we have a Sales checkmarkbox and it selects all the groups required for that role.
    and if this user happens to be for example an international it requires group membership on top of that sales role. so we select the “international” checkmark box?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s