I have a very large number of users that I need to add to an AD group. I have all the users SAMAccountNames
stored in a datagridview.
The code below works but slowly. It's as if it's querying each user directly when I call g.members.add
. Is there a more efficient way to add them?
For Each r As DataGridViewRow In dgvFinalUsers.Rows
Dim userName As String = r.Cells(0).Value
If Not g.Members.Contains(ctx, IdentityType.SamAccountName, userName) Then
g.Members.Add(ctx, IdentityType.SamAccountName, userName)
i += 1
Debug.Print(i)
End If
Next
g.save