Vbscript VBS Active Directory(2003)将用户从一组移动到另一组

Vbscript VBS Active Directory(2003)将用户从一组移动到另一组,vbscript,active-directory,windows-server-2003,active-directory-group,Vbscript,Active Directory,Windows Server 2003,Active Directory Group,我使用这个VBS将用户的平面列表从一个组移动到另一个组。 到现在为止,一直都还不错。我是VB的新手。挑战在于我有20个不同的同步组(Sync01-Sync20)和20个Mig组(Mig01-Mig20)。我需要一个扩展的代码,以确定巫婆Sunc组的用户是成员。然后将其“翻译”为正确的Mig组。有人吗?:) DIM objGroup、objGroup2、objRootLDAP、objFSO、objInput、objConnection、objCommand 暗斯特鲁瑟 出错时继续下一步 设置obj

我使用这个VBS将用户的平面列表从一个组移动到另一个组。 到现在为止,一直都还不错。我是VB的新手。挑战在于我有20个不同的同步组(Sync01-Sync20)和20个Mig组(Mig01-Mig20)。我需要一个扩展的代码,以确定巫婆Sunc组的用户是成员。然后将其“翻译”为正确的Mig组。有人吗?:)

DIM objGroup、objGroup2、objRootLDAP、objFSO、objInput、objConnection、objCommand
暗斯特鲁瑟
出错时继续下一步
设置objRootLDAP=GetObject(“LDAP://rootDSE”)
设置objConnection=CreateObject(“ADODB.Connection”)
打开“Provider=ADsDSOObject;”
设置objCommand=CreateObject(“ADODB.Command”)
objCommand.ActiveConnection=objConnection
设置objFSO=CreateObject(“Scripting.FileSystemObject”)
设置objInput=objFSO.OpenTextFile(“users.txt”)
设置objGroup=GetObject(“LDAP://cn=Sync01,ou=Huset,dc=bb,dc=net”)
设置objGroup2=GetObject(“LDAP://cn=Mig01,ou=Huset,dc=bb,dc=net”)
直到objInput.AtEndOfStream
strUser=ObjInput.ReadLine
objCommand.CommandText=“;(&(objectCategory=person)(sAMAccountName=“&strUser&”);区分名称,userAccountControl;子树
Set objRecordSet=objCommand.Execute
如果objRecordSet.RecordCount=0,则
MsgBox strUser&“未找到!”&VbCrLf&“正在跳过”,VbOkOnly,“未找到用户”
其他的
strnd=objRecordSet.Fields(“区分名称”)
Set objUser=GetObject(“LDAP://”&strnd)
objGroup.Remove(objUser.AdsPath)
objGroup2.Add(objUser.AdsPath)
如果结束
环
WScript.Echo“完成”

如果您只想将组成员从每个同步组转移到相应的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

任何给定同步组的“正确”Mig组是什么?用户是否可以是多个Mig或Sync组的成员?我的问题。如果用户是Sync01的成员,那么正确的grup是Mig01,依此类推。这些组用于控制名为Quest的工具的迁移流。如果将成员添加到错误的组,则迁移将失败。我必须花3-4个小时浏览日志才能找到并纠正问题。谢谢!正如我所说,脚本不是我的强项。我该如何在我的原始脚本中加入这一点?我得到了你写的在我的测试环境中工作的剪报,但是这移动了所有的用户。我需要一种方法来让这段代码与我原来的帖子中的“Users.txt”保持一致。
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