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:

- Search field for users (SamAccountName). No need to enter wildcards.
- Dropdown box for sub-OU’s from the DefaultUserSearchBase variable. It will show the OU from the $DefaultOU variable when starting.
- List of users from the OU (as selected in 2), here you can select users (see also 4 and 6)
- Add button to add users to “Selected users” (6) list.
- Remove button, to remove selected user from “Selected users” (6) list.
- Selected users listbox. If no users are selected here, the script will use the selection in box 3.
- Search/filter field for groups. No need to enter wildcards.
- List of groups to add users to. The filter field (7) can be used to search for wanted groups.
- 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.
- Cancel button. The GUI will close and won’t do anything with the currently selected items.
- 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)
- 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.
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?
LikeLike
Do you mean that you want the selected users box to contain the members of the group that are already in the selected group?
LikeLike
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?
LikeLike
Yes this is possible, there can be found enough information on the internet on how to do this. (Create checkbox powershell / execute powershell code when checking checkbox)
LikeLike