0

我正在使用这个 VBS 将用户的平面列表从一个组移动到另一个组。到目前为止,一切都很好。我是 VB 的菜鸟。挑战在于我有 20 个不同的同步组 (Sync01-Sync20) 和 20 个 Mig 组 (Mig01-Mig20)。我需要扩展识别用户所属的女巫 Sunc 组的代码。然后将其“翻译”为正确的 Mig 组。任何人?:)

DIM objGroup, objGroup2, objRootLDAP, objFSO, objInput, objConnection, objCommand 
DIM strUser 

On Error Resume Next 

Set objRootLDAP = GetObject("LDAP://rootDSE") 
Set objConnection = CreateObject("ADODB.Connection") 
objConnection.Open "Provider=ADsDSOObject;" 
Set objCommand = CreateObject("ADODB.Command") 
objCommand.ActiveConnection = objConnection 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objInput = objFSO.OpenTextFile("users.txt") 
Set objGroup = GetObject("LDAP://cn=Sync01,ou=Huset,dc=bb,dc=net") 
Set objGroup2 = GetObject("LDAP://cn=Mig01,ou=Huset,dc=bb,dc=net") 

Do Until objInput.AtEndOfStream 
strUser = ObjInput.ReadLine 

objCommand.CommandText = "<LDAP://dc=bb,dc=net>;(&(objectCategory=person)(sAMAccountName=" & strUser & "));distinguishedName,userAccountControl;subtree" 

Set objRecordSet = objCommand.Execute 

If objRecordSet.RecordCount = 0 Then 
    MsgBox strUser & " was not found!" & VbCrLf & "Skipping", VbOkOnly,"User Not Found" 
Else 
    strDN = objRecordSet.Fields("distinguishedName") 
    Set objUser = GetObject("LDAP://" & strDN) 
    objGroup.Remove(objUser.AdsPath) 
    objGroup2.Add(objUser.AdsPath)
End If 
Loop 

WScript.Echo "Complete"
4

1 回答 1

0

如果您想要的只是将组成员从每个 Sync 组转移到对应的 Mig 组,应该这样做:

Set fso = CreateObject("Scripting.FileSystemObject")

Set userlist = CreateObject("Scripting.Dictionary")
userlist.CompareMode = vbTextCompare
Set f = fso.OpenTextFile("users.txt")
Do Until f.AtEndOfStream
  userlist.Add f.ReadLine, True
Loop
f.Close

domain = GetObject("LDAP://rootDSE").Get("defaultNamingContext")

For i = 1 To 20
  n = Right("0" & i, 2)
  Set gSync = GetObject("LDAP://CN=Sync" & n & ",OU=Huset," & domain)
  Set gMig  = GetObject("LDAP://CN=Mig" & n & ",OU=Huset," & domain)
  For Each m In gSync.Members
    Set user = GetObject(m.ADsPath)
    If userlist.Exists(user.sAMAccountName) Then
      gMig.Add(m.ADsPath)
      gSync.Remove(m.ADsPath)
    End If
  Next
Next
于 2013-08-22T20:46:02.693 回答