By miketopeCreated 27 Oct 2009, Modified 29 Oct 2009
My Rating:
Vote
Rating:
Not Rated
Views:17800
Downloads:433
Source:

List Members of Groups in OU

Language:  VBScript

Compatibility

Windows XP Yes Windows 2003 Unknown
Windows 2000 Unknown Windows NT Unknown
Vista Unknown Windows 2008 Unknown
Description

List members of groups in OU with fullname.


Notes
Usage:
 
cscript groupmembers.vbs ou=MyUsers,dc=wisesoft,dc=co,dc=uk
 
The script will create a text file called "groupmembers.txt" in the current directory listing the groups in the OU and all the group members.
 
Code

Line Numbers: On  Off      Plain Text
Dim strDomain, objFSO, objOutputFile
strDomain = wscript.arguments.item(0)
if strDomain = "" then
  	wscript.echo "Usage: cscript groupsmembers.vbs <OU Name>"
	wscript.echo "e.g. cscript ou=MyUsers,dc=wisesoft,dc=co,dc=uk"
  	wscript.quit
else
	Set objFso = CreateObject("Scripting.FileSystemObject")
	Set objOutputFile = objFSO.CreateTextFile("groupsmembers.txt", 2, True)
	listOU strDomain

	objOutputFile.Close
	set objOutputFile = nothing
	set objFSO = nothing
end if 'usage

wscript.quit

function listOU(strOU)
	Dim objOU, objM
	set objOU=Getobject("LDAP://" & strOU)
	For each objM in objOU
  		Select case objM.class
    		Case "organizationalUnit"
      			listOU objM.distinguishedName
    		Case "group"
      			listgroup "", objM.distinguishedName
    		Case Else
      			'do nothing
  		End select
	Next
end function

function listgroup(strCrumb, strGroup)
	Dim objG, objM
	'wscript.echo "-- " & strGroup

	if strCrumb <> "" then strCrumb = strCrumb & "/"
	set objG = getObject("LDAP://" & strGroup)
	For each objM in objG.Members
  		Select case objM.class
    			Case "group"
      				if inStr(strCrumb, objM.cn) = 0 then 'prevent circular
        				listgroup strCrumb & objG.cn, objM.distinguishedName
      				end if
    			Case "user"
     				 wscript.echo strCrumb & objG.cn & "," & objM.cn & "," & objM.DisplayName
     				 objOutputFile.WriteLine strCrumb & objG.cn & "," & objM.cn & "," & objM.DisplayName
    			Case Else
      				wscript.echo "-------------" & objG.cn & " " & objM.cn & " " & objM.class
  		End select
	Next
end function

 


Got a useful script? Click here to upload!


 

  Post Comment
Order By:  
User Comments
      

Posted On: 9/28/2018 7:16:35 AM

jinyi928 pandora charms moncler outlet ugg boots outlet longchamp basketballl shoes adidas shoes bottega veneta mbt shoes supreme clothing coach outlet lacoste polo coach outlet christmas presents off white jordan adidas nmd longchamp outlet canada goose outlet canada goose outlet louboutin shoes canadian goose clarks outlet michael kors outlet skechers shoes new balance shoes canada goose moncler outlet coach outlet true religion salomon shoes off white shoes clarks outlet james harden shoes ray ban sunglasses ralph lauren polo pandora champion sportswear tory burch outlet coach outlet kate spade outlet michael kors outlet mlb jerseys nike tn ralph lauren polo oakley sunglasses true religion jeans champion clothing christian louboutin outlet christian louboutin shoes adidas superstar clarks shoes ralph lauren polo red bottom shoes pandora jewelry ralph lauren uk red bottom shoes moncler outlet canada goose jackets coach outlet coach outlet online canada goose outlet coach outlet converse trainer ecco shoes nike outlet superdry uk coach outlet online ugg outlet clearance canada goose outlet kate spade handbags adidas yeezy coach outlet jordan uk canada goose jacket hermes belt hogan shoes jordans ray ban sunglasses supreme ray ban sunglasses ray ban sunglasses true religion jeans outlet north face coach handbags ugg boots off white clothing canada goose ralph lauren polo christian louboutin shoes ralph lauren uk canada goose clothing coach outlet ugg outlet boots coach factory outlet air max 90 christian louboutin outlet christian louboutin off white outlet ugg outlet jordan shoes pandora charms asics shoes nike shoes outlet christian louboutin outlet moncler jackets ed hardy uk fitflops clearance ugg boots christian louboutin outlet michael kors outlet canada goose outlet pandora outlet tod's outlet manolo blahnik canada goose outlet red bottom shoes nike shoes salomon shoes nike blazers coach outlet dsquared2 ralph lauren fitflops clearance north face true religion jeans canada goose jackets pandora jewelry true religion jeans outlet jordans louboutin shoes asics shoes coach outlet nhl jersey jordan clothing yeezy boots 350 nike shoes nike shoes coach outlet online nike outlet factory jordan 8 fitflops clearance ralph lauren polo jordan shoes canada goose outlet jordan 4 adidas yeezy giuseppe zanotti kate spade outlet true religion canada goose nike clothing louboutin shoes nike air max mbt shoes issey miyake ferragamo belt air max 90 ultra boost 3.0 birken stock moncler outlet ugg boots canada goose outlet moncler outlet moncler jackets hogan shoes coach factory outlet louboutin shoes stussy ugg boots clearance true religion jeans soccer shoes pandora outlet pandora charms ugg boots ecco shoes canada goose outlet kate spade outlet jordan shoes nba jerseys reebok outlet adidas clothing louboutin shoes michael kors outlet fitflops clearance adidas clothing vibram five fingers coach outlet ray ban sunglasses nike shoes fidget spinner ralph lauren polo christian louboutin pandora jewelry coach outlet online pandora charms clarks shoes christian louboutin coach outlet coach outlet factory coach outlet kate spade outlet moncler jacket ugg outlet canada goose outlet mbt shoes ugg outlet ferragamo shoes valentino shoes red bottom shoes christian louboutin shoes pandora outlet prada handbags ralph lauren polo moncler outlet coach factory outlet coach outlet christian louboutin shoes kate spade outlet michael kors outlet ralph lauren polo longchamp outlet ralph lauren uk hermes belt coach outlet adidas outlet hugo boss kate spade nike shoes canada goose outlet hugo boss louboutin shoes jordan shoes prada shoes ugg boots clearance christian louboutin outlet supreme clothing ugg outlet air max 90 dsquared2 christian louboutin outlet christian louboutin nike huarache coach factory outlet