Devide 1000 users to 3 groups

Hi there
i am wondering what are my options in terms of away to devide 1000 users to 3 groups of users that i need to create diffrent tasks for.
all 1000 users are in a specific ou in active directory.
i know i can probably just query and export them to txt manually devide them to 3 txt files and then import each and do the task for that group.
seems kind of “manual” to me
i was wondering if someone has any other ideas ?

Thanks in advance

It depends on whether you want to divide the users randomly, take 1-333, 334-666, 667-1000 or there is some criteria you’re going to use to split up the users

Thanks for your reply
i just need to divide them to 3 ,basically to divide the load on the servers im running the task on.
ill drop each “job/batch” on a different server
that’s my intention

This will work. May not be the best code.

Will group users based on the last number in their SID. Won’t be perfectly balanced, but will work for your use case.

Get-ADUser -filter * | Group-Object -Property {$.SID.Value.Substring(43,1) -le 3},{$.SID.Value.Substring(43,1) -gt 3 -and $.SID.Value.Substring(43,1) -le 6},{$.SID.Value.Substring(43,1) -ge 7}

If you’re looking for a “Round Robin” solution then you could use a counter.

$users = # you need to populate this with e.g. Get-ADUser -Filter * -SearchBase "The DN of the OU"

$counter = 1

foreach($u in $users)
  1 { Add-ADGroupMember -Identity "The First Group" -Members $u.SamAccountName; $counter++; break;}
  2 { Add-ADGroupMember -Identity "The Second Group" -Members $u.SamAccountName; $counter++; break;}
  3 { Add-ADGroupMember -Identity "The Third Group" -Members $u.SamAccountName; $counter = 1; break;}

Just replace Add-ADGroupMember with whatever you want to do with them.
Just used that as an example.