?
Solved

Problem to Export Group's member from active directory

Posted on 2008-02-06
5
Medium Priority
?
2,135 Views
Last Modified: 2012-08-13
Hi all :)
I've a VBscript that list all my group in a file and then i read that file to export the member of that Group.
when i execute it' it said that my variable are not a collection.

I pass all the day trying to figure out what the problem is :S

Thanks for your Help
Error.txt
0
Comment
Question by:morijona
5 Comments
 
LVL 8

Expert Comment

by:JjcampNR
ID: 20836082
Try this, it's worked fine for me.
' GroupEnum.vbs
' VBScript to discover who is a member of the Administrators Group
' Author Guy Thomas http://computerperformance.co.uk/
' Version 1.3 August 2005
' ----------------------------------------------------------' 
Option Explicit
Dim strMember, strDNSDomain, strContainer
Dim objGroup, objRootDSE
Dim arrMemberOf
 
'  Bind to Active Directory' 
strContainer = "cn=Administrators,cn=Builtin, "
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
 
'  Get the Builtin Administrators group
Set objGroup = GetObject ("LDAP://"& strContainer & strDNSDomain)
objGroup.getInfo
 
arrMemberOf = objGroup.GetEx("member")
 
' Loop = For Each .... Next 
' WScript.Echo "Members of Group " & strContainer
For Each strMember in arrMemberOf
   WScript.echo strMember
Next
 
Wscript.Quit
 
' End of Sample Group Enum Member Script

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20836180
Hi, this is a script that I use to get the members of a specific group, which could easily take input of group names from a text file:

'=====================
Set wshNetwork = WScript.CreateObject( "WScript.Network" )
strUserDomain = wshNetwork.UserDomain
strUserComputer = wshNetwork.ComputerName
strUserName = wshNetwork.UserName

strGroup = InputBox("Please type the AD group name to get members of:", "Group Name", "mf_users")
Set objWinntObject = GetObject("WinNT://" & strUserDomain & "/" & strGroup)

strResults = "Results" & VbCrLf & "======="
strResults = strResults & VbCrLf & "Group: " & objWinntObject.Name
strMembers = GetMembers(GetObject("WinNT://" & strUserDomain & "/" & objWinntObject.Name))
strResults = strResults & VbCrLf & strMembers & VbCrLf

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile("DomainGroups.txt", True)
objOutputFile.Write strResults
objOutputFile.Close
Set objOutputFile = Nothing
Set objFSO = Nothing

MsgBox "Done.  Please see output text file."

Function GetMembers(objGroup)      
      strMembers = ""
      
      For Each objMember In objGroup.Members
            If strMembers = "" Then
                  strMembers = objMember.Name
            Else
                  strMembers = strMembers & VbCrLf & objMember.FullName
            End If
      Next
      GetMembers = strMembers
End Function
'=====================

Regards,

Rob.
0
 
LVL 17

Expert Comment

by:Jared Luker
ID: 20836670
If your just looking for group membership, then you could just use the showmbrs.exe utility from the server resource kit.  I use it all the time for a quick listing of a particular group.
0
 
LVL 23

Accepted Solution

by:
Malli Boppe earned 1000 total points
ID: 20838243
below script give all the members of all groups in the domain.


Option Explicit

Dim objConnection, objCommand, objRecordSet, objGroup, objRootDSE,objFile, objFileSystem, objMember
Dim strLine

Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.OpenTextFile("Groups.xls", 2, True, 0)
objFile.WriteLine "Group Name" & VbTab & "Number of Members" & VbTab & "Members"


Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

Set objRootDSE = GetObject("LDAP://RootDSE")
objCommand.CommandText = "SELECT name, aDSPath,mail " &_
      "FROM 'LDAP://" & objRootDSE.Get("defaultNamingContext") & "' WHERE objectClass='group'"
Set objRootDSE = Nothing

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 600
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF
      Set objGroup = GetObject(objRecordSet.Fields("aDSPath"))
      
            strLine = objRecordSet.Fields("name") & VbTab
            
            strLine = strLine & objGroup.Members.Count & VbTab
            

            For Each objMember in objGroup.Members
                  strLine = strLine & objMember.Get("name") & ","
            Next

            If Right(strLine, 1) = "," Then
                  strLine = Left(strLine, Len(strLine) - 1)
            End If
            objFile.WriteLine strLine
      
      Set objGroup = Nothing
      objRecordSet.MoveNext
Wend

objConnection.Close
Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing

Set objFile = Nothing
Set objFileSystem = Nothing
0
 

Author Closing Comment

by:morijona
ID: 31428666
Thanks alot :)
0

Featured Post

Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Loops Section Overview

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question