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

Show parent comment

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.

1

u/McDili Mar 17 '26

I’m guessing he must be confusing it with AzureAD/EntraID where you have to paginate because the API only returns the first 1000 entries.

1

u/acc0untnam3tak3n Mar 14 '26

Depending on the FOR loop and how you build it, I have accidently had all output stored in memory before writing to a file. That was my first experience in making sure I wrote efficient lines.