AD Script to add/check groups and members

Posted on 2012-08-21
Last Modified: 2012-10-03

I've been given an excel file with around 3,000 groups and it associated members for each group.

An extract from the excel sheet looks something like this:

Column A                Column B
GroupA                    john.smith
GROUPB                  sally.carters
GROUPB                  connel.valentine
GROUPC                  raymond.simons
GROUPC                  william.soans

I've recieved some scripting to create the 3000 groups, so at the moment, I already have the groups created in AD. Now, I require some script to populate each group with members from the excel file i have above. It should follow the below logic:

- Check group name from column A
- Retrieve member name from column B
- Find the group in AD with the group name from column A
- Check if the group already has the member retrieved from column B
- If no, then add the member, if yes, then skip and go to the next row in the excel file

Can anyone suggest some scripts on how i can achieve this?

Thanks for the support.
Question by:connelvalentine
    LVL 23

    Accepted Solution

    You can even do it directly. Just add the member to the group. If the member is not there then it would be added. If is it a member then you get a small error message.

    You need the DSMOD command.

    dsmod group -addmbr "CN=Steven Carroll,CN=Users,DC=windowstoolkit,DC=local"

    There are more examples on that link.

    Author Comment


    Thanks for the input, but i require code that will read the excel file and get it's information from there, and then go to the next line.

    Kind of a FOR EACH...NEXT statement to be incorporated to traverse through the 300 lines.


    Author Closing Comment

    Not  a complete answer

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now