我正在使用此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"
答案 0 :(得分: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