Option Explicit Sub OutputGroupMembership() Dim varGroups, varItem Dim wksOut As Worksheet Dim rngOut As Range Dim varMembers Dim lngIndex As Long Dim strMemberlist As String ' this is the worksheet where the list will go ' adjust as required Set wksOut = ActiveSheet With wksOut ' add titles .Range("A1").Value = "Group name" .Range("B1").Value = "Member ID" ' first output cell Set rngOut = .Range("A2") End With ' this is the list of groups you want to get the members for varGroups = Array("Group 1", "Group 2") For Each varItem In varGroups ' output group name With rngOut .Value = varItem .Font.Bold = True End With ' move down a row Set rngOut = rngOut.Offset(1) ' get member list ' returned as a comma separated list strMemberlist = GetGroupUsers(varItem) ' split list into an array varMembers = Split(strMemberlist, ",") ' loop and output member IDs For lngIndex = LBound(varMembers) To UBound(varMembers) rngOut.Offset(, 1).Value = varMembers(lngIndex) Set rngOut = rngOut.Offset(1) Next lngIndex Next varItem End Sub Function GetGroupUsers(ByVal strGroupName As String) As String Dim objGroup, objDomain, objMember Dim strMemberlist As String, strDomain As String On Error Resume Next Set objDomain = GetObject("LDAP://rootDse") strDomain = objDomain.Get("dnsHostName") Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroupName & ",group") For Each objMember In objGroup.Members strMemberlist = strMemberlist & "," & objMember.Name Next objMember ' strip off the leading comma GetGroupUsers = Mid$(strMemberlist, 2) End Function
|Questions regarding decommissioning an enterprise certificate authority in Server 2008||1||20|
|AD reporting and update tool||9||55|
|Sending Attachment via CDO||3||22|
|Obtaining a computer ssl certificate from AD PKI using the command line||2||16|
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
11 Experts available now in Live!