VBScript; List AD Group Members

The script below will list all members of a particular group within AD.

The script should be called as follows from a  command window: cscript.exe script_name.vbs > Group-Members.txt

This will ‘pipe’ the results into a text file in the same folder as the vbs file.


‘—————————- Begin Copy Here

Dim arrNames()

intSize = 0

Set objGroup = GetObject(“LDAP://CN=Merchandising,OU=Security Groups,OU=UK,DC=mydom,DC=com”)

For Each strUser in objGroup.Member
    Set objUser =  GetObject(“LDAP://” & strUser)
    ReDim Preserve arrNames(intSize)
    arrNames(intSize) = objUser.CN
    intSize = intSize + 1

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

For Each strName in arrNames
    Wscript.Echo strName

‘—————————- End Copy Here