Avatar of Massimiliano Loi
Massimiliano LoiFlag for Switzerland

asked on 

Script to Add users to Groups specified into txt file (Active Directory)

Hi guys!
I need to add users into groups by creating these groups if they doesn't exist yet.

I would start from a txt file containing users and groups like that:

Surname Name#Administrative
Surname2 Name2#Sell
Surname3 Name3#Administrative

I need to read each row for each user and each group, create the group if it doesn't exist in AD by adding a suffix "Office_" (so the new group will be "Office_Administrative", following the txt example I first wrote) and add the user to the group.

Thx in advance!
Active Directory

Avatar of undefined
Last Comment
Massimiliano Loi
Avatar of Krzysztof Pytko
Krzysztof Pytko
Flag of Poland image

OK, first we need to get some more details before we can start. Where these users and groups should be created (which OU) ?

Then we can start using for that Microsoft DS Tools or Quest PowerShell module for AD.

Thanks in advance for more information

Avatar of Massimiliano Loi


Hi Siek, thx for your reply.
The OU will be "OU=Test,DC=Mydomain,DC=local"

I've installed the Quest PowerShell module for AD yet :)
OK, give me a little time and I will post script for that :)

Avatar of Massimiliano Loi
Massimiliano Loi
Flag of Switzerland image

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Great, so try with "-ErrorAction SilentlyContinue"

Avatar of Massimiliano Loi


Thx Krzysztof, but I really don't know if this could be useful for me, because my script doesn't stop on error, but it still continue working until the end of the loop "foreach".

Instead, I'm doing some test and I got some problem by redirecting the errors I get into a log file, to understand which groups and users fail during the loop. I'm also having another kind of problem: it seems that sometimes this script add the first user it founds into the third group (that is "of another user"), and I don't know why...

Avatar of Massimiliano Loi


I found the solution by myself
Active Directory
Active Directory

Active Directory (AD) is a Microsoft brand for identity-related capabilities. In the on-premises world, Windows Server AD provides a set of identity capabilities and services, and is hugely popular (88% of Fortune 1000 and 95% of enterprises use AD). This topic includes all things Active Directory including DNS, Group Policy, DFS, troubleshooting, ADFS, and all other topics under the Microsoft AD and identity umbrella.

Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews


IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo