[gptalk] Re: How to get the list of users in a group.

  • From: "Bean, Scott" <Scott.Bean@xxxxxxxxxxxxxxxxxx>
  • To: "'gptalk@xxxxxxxxxxxxx'" <gptalk@xxxxxxxxxxxxx>
  • Date: Fri, 14 Nov 2008 10:22:18 -0500

Sorry a little slow, but here is one that you input via an input box and it 
writes a txt file groupmembership.txt to the root of your C drive.




'Input box for computername
Input = InputBox("Enter DN Ldap Path" & VbCrLf & "For Example:" & VbCrLf & 
VbCrLf & "cn=someGrp,ou=someOU,dc=Domain,dc=com","Get Group Membership")
strLdapPath = Input
If strLdapPath = "" Then
WScript.Quit
End If
'=============================================================================================
On Error Resume Next

Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D

Set objGroup = GetObject("LDAP://" & strLdapPath)

'ObjOU.Filter= Array("member")

'Prepare Text File
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.OpenTextFile("C:\GroupMembership.txt", ForWriting, True)
'=============================================================================================


'Write Info to Text File
For Each objGroup in objOU
    objTS.WriteLine objGroup.cn & " Members: "
    arrMemberOf = objGroup.GetEx("member")

    If Err.Number <>  E_ADS_PROPERTY_NOT_FOUND Then
        For Each strMember In arrMemberOf
            objTS.WriteLine vbTab & strMember
        Next
    Else
        objTS.WriteLine vbTab & "memberOf attribute is not set"
        Err.Clear
    End If
Next
    objTS.Close
WScript.Echo "Finished Writing to Text File c:\GroupMembership.txt."











-----Original Message-----
From: gptalk-bounce@xxxxxxxxxxxxx [mailto:gptalk-bounce@xxxxxxxxxxxxx] On 
Behalf Of rpo
Sent: Friday, November 14, 2008 9:27 AM
To: gptalk@xxxxxxxxxxxxx
Subject: [gptalk] Re: How to get the list of users in a group.

hi again,

sorry it's late, i'm tired.

just realised the replacement line i gave you is incorrect. my apologies.

so either use the alternate script aaron has offered, or the actual
correct line i meant to offer is:

GetObject("LDAP://CN=pm_anim_artists,ou=Users,DC=Tai3D,DC=com")

daniel.


On 15/11/2008, Aaron Rabinowitz <rabino67@xxxxxxxxx> wrote:
> I used the following script that I got off a forum that worked ggreat,
> you only ahve to change the second line. and it will dispaly all the
> suers in excel
>
>
>
> Dim objGroup, objExcel, iRow, strUser
> Set objGroup = GetObject("LDAP://CN=xxxxxxxx,ou=yyyyyy,dc=domain,dc=com")
>
> Set objExcel = CreateObject("Excel.Application")
> With objExcel
>  .SheetsInNewWorkbook = 1
>  .Workbooks.Add
>  .Visible = True
>  .Worksheets.Item(1).Name = mid(objGroup.Name,
> instr(1,objGroup.Name,"=") + 1 ) 'set Worksheet name to that of the DL
>  irow=1
>
>  For Each strUser in objGroup.Member
>    Set objUser =  GetObject("LDAP://" & strUser)
>    .Cells(iRow,1) = objUser.CN
>    irow=irow + 1
>  Next
>  .Columns(1).entirecolumn.autofit
> End With
>
> Set objExcel = Nothing
> Set objGroup = Nothing
>
>
>
>
> On Fri, Nov 14, 2008 at 9:10 AM, rpo <rpo8373@xxxxxxxxx> wrote:
> > hi ananth,
> >
> > this isn't really gpo related. and by not really, i mean...not at all.
> >
> > nevertheless, replace the following line:
> >
> > GetObject("LDAP://CN=pm_anim_artists,DC=Tai3D,DC=com")
> >
> > with:
> >
> > GetObject("LDAP://CN=pm_anim_artists,cn=Users,DC=Tai3D,DC=com")
> >
> > should do the trick i reckon. good luck.
> >
> > daniel.
> >
> >
> > On 14/11/2008, Ananth Rajagopal <ananth.rg@xxxxxxxxx> wrote:
> >> Hi All,
> >>
> >> We are having a 300 user AD. According to project needs we have created
> >> several groups. Now we wold like to get the list of users in these groups.
> >>
> >> We got a script from MS Scriptcenter, but it is returning an error....
> >> please advice....
> >>
> >> I've attached an image of our users and groups.
> >>
> >> Dim arrNames()
> >> intSize = 0
> >>
> >> Set objGroup =
> >> GetObject("LDAP://CN=pm_anim_artists,DC=Tai3D,DC=com")
> >>
> >> For Each strUser in objGroup.Member
> >>     Set objUser =  GetObject("LDAP://" & strUser)
> >>     ReDim Preserve arrNames(intSize)
> >>     arrNames(intSize) = objUser.CN
> >>     intSize = intSize + 1
> >> Next
> >>
> >> For i = (UBound(arrNames) - 1) to 0 Step -1
> >>     For j= 0 to i
> >>         If UCase(arrNames(j)) > UCase(arrNames(j+1)) Then
> >>             strHolder = arrNames(j+1)
> >>             arrNames(j+1) = arrNames(j)
> >>             arrNames(j) = strHolder
> >>         End If
> >>     Next
> >> Next
> >>
> >> For Each strName in arrNames
> >>     Wscript.Echo strName
> >> Next
> >>
> >> We are "There is no such object on the server" message. Selected users are
> >> members of ordinary groups. So we are wondering where we went wrong.
> >>
> >> Thanks and regards
> >> Ananth.
> >>
> >>
> > ***********************
> > You can unsubscribe from gptalk by sending email to 
> > gptalk-request@xxxxxxxxxxxxx with 'unsubscribe' in the Subject field OR by 
> > logging into the freelists.org Web interface. Archives for the list are 
> > available at http://www.freelists.org/archives/gptalk/
> > ************************
> >
> ***********************
> You can unsubscribe from gptalk by sending email to 
> gptalk-request@xxxxxxxxxxxxx with 'unsubscribe' in the Subject field OR by 
> logging into the freelists.org Web interface. Archives for the list are 
> available at http://www.freelists.org/archives/gptalk/

> ************************
>
***********************
You can unsubscribe from gptalk by sending email to 
gptalk-request@xxxxxxxxxxxxx with 'unsubscribe' in the Subject field OR by 
logging into the freelists.org Web interface. Archives for the list are 
available at http://www.freelists.org/archives/gptalk/
************************
***********************
You can unsubscribe from gptalk by sending email to 
gptalk-request@xxxxxxxxxxxxx with 'unsubscribe' in the Subject field OR by 
logging into the freelists.org Web interface. Archives for the list are 
available at http://www.freelists.org/archives/gptalk/
************************

Other related posts: