'====================================================================
'= Show Domain Groups and Members VBScript sample - Copyright © 2007, Dave Moats
'=
'= This sample is provided 'as-is', without any express or implied warranty.
'= In no event will the authors be held liable for any damages arising from
'= the use of this sample code.
'=
'= Permission is granted to anyone to use this sample code for any purpose,
'= including commercial applications, subject to the following restrictions:
'=
'= The origin of this code must not be misrepresented;
'= you must not claim that you wrote the original code.
'= If you use this code, an acknowledgment in the
'= documentation is requested - shown below:
'=
'= Portions Copyright © 2007, Dave Moats (http://www.davemoats.com/).
'=
'====================================================================
'====================================================================
'==
'== showGroupMembers - script to list all the groups and the members
'== of a group in a specified domain. if one of
'== the members is a group then that group will
'== be enumerated also
'==
'====================================================================
set fso = createobject ( "Scripting.FileSystemObject")
'====================================================================
'== get the info required to run the script
'====================================================================
if wscript.arguments.count = 0 then
wscript.echo ( "Usage: showGroupMembers.vbs <Domain> <Path to Ouput file>")
domName = inputbox ( "Enter the domain that you want to get the groups for:")
outPath = inputbox ( "Enter the path to the output file:")
elseif wscript.arguments.item ( 0) = "/?" Or wscript.arguments.item ( 0) = "-?" then
wscript.echo ( "Usage: showGroupMembers.vbs <Domain> <Path to Ouput file>")
wscript.quit ( )
else
domName = wscript.arguments.item ( 0)
outPath = wscript.arguments.item ( 1)
end if
'====================================================================
'== make sure we have some info
'====================================================================
if domName = "" or outPath = "" then
wscript.echo ( "There were not enough arguments passed to the script")
wscript.echo ( "Usage: showGroupMembers.vbs <Domain> <Path to Ouput file>")
wscript.quit ( )
end if
'====================================================================
'== open the output file
'====================================================================
set outputFile = fso.createtextfile ( outPath)
on error resume next
'====================================================================
'== Bind to the NT4 domain we are interested in
'====================================================================
domPath = "WinNT://" & domName
domFilter = array ( "Group")
set domObj = getobject ( domPath)
'====================================================================
'== Apply the filter to the returned object
'====================================================================
domObj.filter = domFilter
'====================================================================
'== Go through the list of groups displaying the members
'====================================================================
for each grp in domObj
if grp.Name <> "Domain Users" and grp.Name <> "Domain Computers" then
outputFile.writeline ( "Group - " & stripProvider ( grp.ADsPath) )
'==============================================================
'== Check each member of the group - if it is a group enumerate it
'==============================================================
for each member in grp.members
if member.Class= "Group" and member.Name <> "Domain Users" and member.Name <> "Domain Computers" then
outputFile.writeline ( " Group - " & stripProvider ( member.ADsPath) )
enumGroup member.ADsPath
elseif member.Name = "Domain Users" then
outputFile.writeline ( " Group - " & stripProvider ( member.ADsPath) )
else
outputFile.writeline ( " User - " & stripProvider ( member.ADsPath) )
end if
next
end if
outputFile.writeline ( " ")
next
'====================================================================
'== dump the reference to the domain
'====================================================================
set domObj = nothing
'====================================================================
'== clean up the out file reference and the file system object
'====================================================================
outputFile.close
set outputFile = nothing
set fso = nothing
wscript.quit ( )
'====================================================================
'== sub routine to enumerate group's members
'====================================================================
sub enumGroup ( grpPath )
'==================================================================
'== bind to the group whose members we want
'==================================================================
set eGroup = getobject ( grpPath)
'==================================================================
'== loop through the list of groups displaying the members
'==================================================================
for each member in eGroup.members
outputFile.writeline ( " User - " & stripProvider ( member.ADsPath) )
next
'==================================================================
'== dump the group object reference
'==================================================================
set eGroup = nothing
end sub
'====================================================================
'== function to return an object's domain from its ADsPath
'====================================================================
function stripProvider ( inVal )
iLoc = instr ( 1, inVal, "/" )
tmpStr = mid ( inVal, iLoc+2, len ( inVal) )
stripProvider = tmpStr
end function
'= Show Domain Groups and Members VBScript sample - Copyright © 2007, Dave Moats
'=
'= This sample is provided 'as-is', without any express or implied warranty.
'= In no event will the authors be held liable for any damages arising from
'= the use of this sample code.
'=
'= Permission is granted to anyone to use this sample code for any purpose,
'= including commercial applications, subject to the following restrictions:
'=
'= The origin of this code must not be misrepresented;
'= you must not claim that you wrote the original code.
'= If you use this code, an acknowledgment in the
'= documentation is requested - shown below:
'=
'= Portions Copyright © 2007, Dave Moats (http://www.davemoats.com/).
'=
'====================================================================
'====================================================================
'==
'== showGroupMembers - script to list all the groups and the members
'== of a group in a specified domain. if one of
'== the members is a group then that group will
'== be enumerated also
'==
'====================================================================
set fso = createobject ( "Scripting.FileSystemObject")
'====================================================================
'== get the info required to run the script
'====================================================================
if wscript.arguments.count = 0 then
wscript.echo ( "Usage: showGroupMembers.vbs <Domain> <Path to Ouput file>")
domName = inputbox ( "Enter the domain that you want to get the groups for:")
outPath = inputbox ( "Enter the path to the output file:")
elseif wscript.arguments.item ( 0) = "/?" Or wscript.arguments.item ( 0) = "-?" then
wscript.echo ( "Usage: showGroupMembers.vbs <Domain> <Path to Ouput file>")
wscript.quit ( )
else
domName = wscript.arguments.item ( 0)
outPath = wscript.arguments.item ( 1)
end if
'====================================================================
'== make sure we have some info
'====================================================================
if domName = "" or outPath = "" then
wscript.echo ( "There were not enough arguments passed to the script")
wscript.echo ( "Usage: showGroupMembers.vbs <Domain> <Path to Ouput file>")
wscript.quit ( )
end if
'====================================================================
'== open the output file
'====================================================================
set outputFile = fso.createtextfile ( outPath)
on error resume next
'====================================================================
'== Bind to the NT4 domain we are interested in
'====================================================================
domPath = "WinNT://" & domName
domFilter = array ( "Group")
set domObj = getobject ( domPath)
'====================================================================
'== Apply the filter to the returned object
'====================================================================
domObj.filter = domFilter
'====================================================================
'== Go through the list of groups displaying the members
'====================================================================
for each grp in domObj
if grp.Name <> "Domain Users" and grp.Name <> "Domain Computers" then
outputFile.writeline ( "Group - " & stripProvider ( grp.ADsPath) )
'==============================================================
'== Check each member of the group - if it is a group enumerate it
'==============================================================
for each member in grp.members
if member.Class= "Group" and member.Name <> "Domain Users" and member.Name <> "Domain Computers" then
outputFile.writeline ( " Group - " & stripProvider ( member.ADsPath) )
enumGroup member.ADsPath
elseif member.Name = "Domain Users" then
outputFile.writeline ( " Group - " & stripProvider ( member.ADsPath) )
else
outputFile.writeline ( " User - " & stripProvider ( member.ADsPath) )
end if
next
end if
outputFile.writeline ( " ")
next
'====================================================================
'== dump the reference to the domain
'====================================================================
set domObj = nothing
'====================================================================
'== clean up the out file reference and the file system object
'====================================================================
outputFile.close
set outputFile = nothing
set fso = nothing
wscript.quit ( )
'====================================================================
'== sub routine to enumerate group's members
'====================================================================
sub enumGroup ( grpPath )
'==================================================================
'== bind to the group whose members we want
'==================================================================
set eGroup = getobject ( grpPath)
'==================================================================
'== loop through the list of groups displaying the members
'==================================================================
for each member in eGroup.members
outputFile.writeline ( " User - " & stripProvider ( member.ADsPath) )
next
'==================================================================
'== dump the group object reference
'==================================================================
set eGroup = nothing
end sub
'====================================================================
'== function to return an object's domain from its ADsPath
'====================================================================
function stripProvider ( inVal )
iLoc = instr ( 1, inVal, "/" )
tmpStr = mid ( inVal, iLoc+2, len ( inVal) )
stripProvider = tmpStr
end function
Copyright © 2010 Dave Moats. All rights reserved. Links: Copyright © by their respective owners.
NO WARRANTIES EXTENDED. Void where prohibited by law. Please report any issues or broken links.
You may link to this site freely from your own site. You may quote from this site, but please include a link to the original source on the originating site.