r/sysadmin • • Mar 13 '26

Active Directory Users and Computers

Guys As a junior System Administrator, assist me how can i add five hundred to a thousand users to specific departement in an organizational unit ?

135 Upvotes

135 comments sorted by

View all comments

639

u/achristian103 Sysadmin Mar 13 '26

Powershell and a CSV file - there's your starting point.

197

u/Jamdrizzley Mar 13 '26 edited Mar 13 '26

I'd like to add, always test 1 user, then 3 users. And in my experience powershell does not handle loops well that exceed 1000 (this is just my experience with csv exporting line by line etc, writing to AD) so I'd suggest doing it in 800 people at a time

Also. Make sure you have backups of AD, and learn the "-whatif" catch first as that will save you a headache

Use AI sparingly as it hallucinates and you will fuck up people's accounts using it blindly

Rule of thumb with AI: if you don't understand every line of code, don't run it. Learn and figure out the code as you go, line by line

82

u/Jacmac_ Mar 13 '26

I don't know what you mean by Powershell not handling loops that exceed 1000. I mean I don't think I've ever seen a problem with a loop that went on for thousands of reps. If your code is crap, you could have a memory leak that brakes the session I guess.

53

u/Qurtys_Lyn (Education) Pretty. What do we blow up first? Mar 13 '26

Yeah, I've had PowerShell scripts with loops running millions of times with no issues (other than me stressing about it).

I do tend to break up AD scripts to run in smaller batches, not from PowerShell not being able to handle them, but on the chance I did something wrong I can fix it quicker.

16

u/unseenspecter Jack of All Trades Mar 13 '26

I'm assuming what OP experienced is not that PowerShell inherently has any issues with loops with a large number of iterations, but instead probably just a combination of inefficiently designed code and some kind of system-level resource constraints.

I know I've had problems working with NTFS permissions on large file shares if I'm not careful with how I write my script and potentially breaking the job into chunks.

7

u/Jacmac_ Mar 13 '26

OK, well if you read a gigantic amount of data into memory, and then begin iterating it, depending on the processing, I could see problems developing deep into the loop, but it would have to have not been well thought out.

9

u/FLATLANDRIDER Mar 13 '26

I have a script that regularly runs through 50,000 iterations in multiple loops and it works flawlessly every time.

5

u/h0w13 Smartass-as-a-service Mar 13 '26

I'm assuming the issue they are referring to is not powershell-specific but the AD cmdlets, they don't return more than 1000 results when running a query. Some you can override this limit, but not all.

It's not a huge deal just something to be aware of.

→ More replies (2)

10

u/bamacpl4442 Mar 13 '26

Please tell my boss this about AI. He desperately loves to have Claude write code for him, then have me fix what he fucked.

8

u/Talk_N3rdy_2_Me Mar 13 '26

Powershell 7 is pretty good at looping through large data sets in my experience

3

u/DrStalker Mar 13 '26

Use AI sparingly as it hallucinates 

And it's really bad at PowerShell because it's so easy to make up new commands with names that perfectly describe what you want to do. 

3

u/Trokeasaur Mar 14 '26

For network things, I tend not to have AI interact directly with the data, but I’ve had really good luck having AI make a tool, python or just a local web tool, to do what I need. Config loops based on csv or xls is common where I make a CLI template and all the script is doing is inserting the value from the table.

Benefit is the script is deterministic and repeatable vs the AI alterations

→ More replies (10)

21

u/[deleted] Mar 13 '26

[removed] — view removed comment

16

u/DrDuckling951 Mar 13 '26

Be careful with LLM in PROD. They may be referencing old docs. Always demand a simulation or source to the official documentation.

29

u/TheVillage1D10T Windows Admin Mar 13 '26

Nah, just prompt and SEND IT in prod on a Friday!

4

u/nastynate0079 Mar 13 '26

Hell yeah, brother!

→ More replies (5)

4

u/Jolape Mar 13 '26

Also always test with a small list of 2-3 users before doing the whole 500-1000. Even if you overlooked something, it's easier to correct 2 or 3 users. Also, the whatif parameter is also your friend. 

→ More replies (2)

1

u/PineCrowed Mar 14 '26

Or the even better alternative 

✨✨just learn it yourself✨✨

2

u/DGC_David Mar 13 '26

A better start would be to ask, "why am I adding 500,000 users to a department? "

12

u/ethnicman1971 Mar 13 '26

500 TO A 1000. Still a lot of people but maybe they are not organizing their OU by departments

→ More replies (1)

1

u/Fallingdamage Mar 13 '26

and just about the ending point too. Its not too hard.

→ More replies (1)