Jump to content

PowerShell - Create AD Groups and Add Multiple Users / Multiple Groups


Recommended Posts

Posted

Hi all,

 

We get our "mailing list" exports from our student database which is basically a CSV of student username and AD Group (Global Distribution). This export is between 7-8,000 lines (7,764 looking at the current export). I am looking for a way to script the creation of these groups and adding the users to these groups. The groups do change over time, so I usually delete all groups, recreate the latest groups and then add them in. This is done via multiple methods but ideally I want it all in one snazzy script - guessing PowerShell.

 

- Not every user is a member of every group.

- Create the group if it doesn't exist (Global Distribution).

- Set a Description of the group.

- Set an Email Address for the group.

 

My PS knowledge is very basic, so all the help that is on offer is greatly appreciated.

 

Cheers

Posted
Pay for Salamander. They save days if not weeks of my time each year, and the school gets that time back with me being productive on new projects, training, development etc. Compare the cost of salamander to the cost of bringing in a contractor each year to do the work you could be doing if you weren't repeating work this work each year, and every time the lists change.
  • Thanks 1
Posted

You’d do something like

$users = Import-csv

Foreach ($user in $users) {

Check if group exists, if not make it

Add user to group

}

 

Relaxing with only an iPad so that’s all I can do for now but should be a decent starter. Check out the Active Directory cmdlets for getting/adding group and for setting group membership.

Posted
An identity solution like MIM would be a good idea you probably get access to it with your licensing (it's a guess). You can do it with scripts and I would be happy to help build these can you anonymous the data in the csv and PM me it so I can take a look.
  • 1 month later...
Posted
You’d do something like

$users = Import-csv

Foreach ($user in $users) {

Check if group exists, if not make it

Add user to group

}

 

Relaxing with only an iPad so that’s all I can do for now but should be a decent starter. Check out the Active Directory cmdlets for getting/adding group and for setting group membership.

 

+1 this, if you are struggling with PowerShell I fully recommend this book

https://www.amazon.co.uk/Learn-Windows-PowerShell-Month-Lunches-dp-1617294160/dp/1617294160/ref=dp_ob_title_bk

 

£30 well spent, PowerShell can be a great tool, and learning it really is easier than you would think.

 

Back to your original question, Katy has it spot on, this is very achievable in PowerShell and in fact would be a great project for you to use to learn.

Posted

I think PowerShell and/or some form of scripting is well worth learning and a skill that is being valued more and more by employers, maybe not so much for support in schools.

 

PowerShell is used in so many ways by so many different solutions, nothing is quicker than scripting for repetitive tasks and it is so much more customizable.

 

One thing to note would be to be careful just running any script found on the Internet and put comments in the script so you and others know at a later date what each bit is doing.

Posted
Yeah Don Jones has done some nice in a month of lunches books, just before lock down packt publishing approached me to write a book on PowerShell unfortunately this year has not turned out quite the way we all wanted.... I know Don is not as involved in PowerShell as he used to be but his book shell of an idea is worth a read along with how to find a wolf in siberia.
Posted
Id agree with using this to develop your PS skills on a 'teach a man to fish' principle. This is ready made for powershell and with compare-object you can even inteligently remove and add people to groups rather than a complete nuke and restart. What is the structure of the CSV, that is presumably where to start?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...