是否使用VBScript导出多个Active Directory组的所有成员?

是否使用VBScript导出多个Active Directory组的所有成员?,vbscript,active-directory,ldap,Vbscript,Active Directory,Ldap,是否有一种方法可以使用VBScript一次导出多个Active Directory组的所有成员?输出最好是他们所属的组下列出的用户名 我有以下允许我一次导出一个广告组的成员,但我不知道如何修改它以查看多个组 On Error Resume Next Set fso = CreateObject("Scripting.FileSystemObject") Set outfile = fso.CreateTextFile("Members.csv") Set objGroup = GetObject

是否有一种方法可以使用VBScript一次导出多个Active Directory组的所有成员?输出最好是他们所属的组下列出的用户名

我有以下允许我一次导出一个广告组的成员,但我不知道如何修改它以查看多个组

On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set outfile = fso.CreateTextFile("Members.csv")
Set objGroup = GetObject("LDAP://cn=*GROUPNAME*,OU=Groups,DC=domain,DC=local")
objGroup.GetInfo

arrMembersOf = objGroup.GetEx("member")

For Each GetObject in ObjGroup
    outfile.WriteLine objGroup.Name
Next

For Each strMember in arrMembersOf
    outfile.WriteLine strMember
Next

有什么想法吗?

找到Active Directory脚本的最佳地点是Microsoft的脚本中心


您可以找到列出所有组和组成员的脚本(“列出域中的所有组和组的所有成员”)。

查找Active Directory脚本的最佳位置是Microsoft的脚本中心


您可以找到一个列出所有组和所有组成员的脚本(“列出域中的所有组和组的所有成员”)。

是的,这是可能的,但我认为您可能需要稍微改变您的方法。您需要编写一个LDAP查询来同时查询两个组,而不仅仅是将范围设置为特定组

因此,请尝试如下方式重新编写脚本:

  Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("defaultNamingContext")
  Set objRootDSE = Nothing
  Set ad = CreateObject("ADODB.Command")
  Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    ad.ActiveConnection = adoConnection

'Put the distinguishedname of your two groups here:
strFilter = "(|(memberof=CN=Group Name,OU=....)(memberof=CN=Group Name 2,OU=....))"

'Chose what you want to return here:
strAttributes = "samaccountname,cn"

strQuery = "<LDAP://" & strDNSDomain & ">" & ";" & strFilter & ";" & strAttributes & ";subtree"

  ad.CommandText = strQuery
  ad.Properties("SearchScope") = 2 
  ad.Properties("Page Size") = 1000
  ad.Properties("Cache Results") = False
Set objRS = ad.Execute

有用吗?我在这里假设您对编写LDAP查询略知一二

是的,这是可能的,但我认为您可能需要稍微改变一下方法。您需要编写一个LDAP查询来同时查询两个组,而不仅仅是将范围设置为特定组

因此,请尝试如下方式重新编写脚本:

  Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("defaultNamingContext")
  Set objRootDSE = Nothing
  Set ad = CreateObject("ADODB.Command")
  Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    ad.ActiveConnection = adoConnection

'Put the distinguishedname of your two groups here:
strFilter = "(|(memberof=CN=Group Name,OU=....)(memberof=CN=Group Name 2,OU=....))"

'Chose what you want to return here:
strAttributes = "samaccountname,cn"

strQuery = "<LDAP://" & strDNSDomain & ">" & ";" & strFilter & ";" & strAttributes & ";subtree"

  ad.CommandText = strQuery
  ad.Properties("SearchScope") = 2 
  ad.Properties("Page Size") = 1000
  ad.Properties("Cache Results") = False
Set objRS = ad.Execute
有用吗?我假设您对编写LDAP查询有一点了解