【问题标题】:Retrieve recursive group membership of an Active Directory user or group in VBS在 VBS 中检索 Active Directory 用户或组的递归组成员身份
【发布时间】:2013-04-03 11:52:21
【问题描述】:

有很多关于如何使用 memberOf 属性的示例,但我找不到任何我需要的工作脚本。所以我自己写了,希望在这里分享我的脚本能帮助到其他人。

下面的脚本有 2 个工作示例。第一个示例Set GroupsOfUser = GetMembership(oAD.UserName, null) 检索当前登录用户的成员资格。第二个示例Set GroupsOfGroup = GetMembership("CN=SomeGroup,OU=MyGroupContainer,DC=MyDomain,DC=local", null) 演示了特定组的成员资格。

下面的函数返回唯一值,不会像大多数示例那样进入无限循环。

【问题讨论】:

  • 善意,但这里没有问题。我怀疑这是否符合 SO 规则。
  • @seeker:问的问题是“回答你自己的问题问答风格”,所以我认为他们鼓励这样做。你知道其他地方可以分享这样的脚本吗?我刚刚发布了另一个..
  • 是的,他们鼓励这样做,但也说“以问题的形式表达”,这就是我所说的“这里没有问题”的意思。干杯!

标签: vbscript active-directory


【解决方案1】:
'Get the recursive groups from the active user
Set oAD = CreateObject("ADSystemInfo")
Set GroupsOfUser = GetMembership(oAD.UserName, null)
MsgBox Join(GroupsOfUser.Items(), "," & vbCrLf)

'Get the recursive groups from a specific group
Set GroupsOfGroup = GetMembership("CN=SomeGroup,OU=MyGroupContainer,DC=MyDomain,DC=local", null)
MsgBox Join(GroupsOfGroup.Items(), "," & vbCrLf)


Function GetMembership(sChild, dMembership)
  'Get AD info on the given Child
  Set oChild = GetObject("LDAP://" & sChild)

  If TypeName(oChild) = "Object" Then
    'Add the Child's canonical name to the array IF it's a group
    If TypeName(dMembership) = "Dictionary" Then
      dMembership.Add oChild.distinguishedName, oChild.CN
    Else
      Set dMembership = CreateObject("Scripting.Dictionary")
    End If

    'If the Child has any parents (=groups), run the same loop for these parents.
    If TypeName(oChild.memberOf) = "Variant()" Then
      oParents = oChild.GetEx("memberOf")
      For Each sParent in oParents
        If Not dMembership.Exists(sParent) Then
          Set dMembership = GetMembership(sParent, dMembership)
        End If
      Next
    End If
  End If

  Set GetMembership = dMembership
End Function

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多