1
我需要將很多用戶添加到AD組中。我將所有用戶SAMAccountNames
存儲在datagridview中。使用AccountManagement將多個用戶添加到AD組*快速*使用AccountManagement
下面的代碼工作,但緩慢。就好像在我撥打g.members.add
時直接詢問每個用戶。有沒有更有效的方法來添加它們?
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
聽起來他想將用戶添加到AD組,而不是一個inmemory集合。 – 2014-09-04 16:55:11
@WiktorZychla [我跑到類似的問題](http://stackoverflow.com/questions/2409432/improving-performance-of-system-directoryservices-accountmanagement)在我的編碼也。 DirectyServices中的很多方法不會緩存「Members」之類的結果,因此每次都會重新查詢。將組中當前成員的列表複製到內存集合中,確實會加速'g.Members.Contains'調用。 – 2014-09-04 16:55:57
@WiktorZychla,通過這種方式添加它,每次迭代時他都不必查詢AD。因此,加快這一進程。 – 2014-09-04 16:56:48