Hi there
I had the same problem long time ago and I cant remember what I did to solve it:(
basically I have an array of lets say 100 users(numbers might change, this is just for testing) which I need to “divide” to X number of “groups” and I want to then add each group members to a group for example(could be some other task).
so I import my big list:
$numbers= import-csv C:\files\out.csv
I the use this function to resize based on whatever size I want in this case 2 since I want 2 in each of the 50 groups:
function Resize-Array ([object]$InputObject, [int]$SplitSize = 100)
{
$length = $InputObject.Length
for ($Index = 0; $Index -lt $length; $Index += $SplitSize)
{
, ($InputObject[$index … ($index + $splitSize – 1)])
}
}
$resizedarray=Resize-Array -InputObject $numbers -SplitSize 50
$resizedarray.count
shows 50
now I want to cycle inside the $rezisedarray(which has 50 “groups”) and inside every “group” to add each of the members of that “group” to the ad group
but that doesn’t seem to work, so I tried write-host to see if I can even show these members and it doesn’t show them:
$resizedarray[0] |%{write-host $_.displayname}
user1
user2
and that shows the users just fine.
any ideas?