'====================================================================
'= Show Distribution List 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/).
'=
'====================================================================
'====================================================================
'==
'== distListMembers.vbs - a script that lists all the members of a
'== distribution list
'==
'====================================================================
set fso = createobject ( "Scripting.FileSystemObject")
'====================================================================
'== get the info required to run the script
'====================================================================
if wscript.arguments.count = 0 then
wscript.echo ( "Usage: distListMembers.vbs <Name of the Dist List> <Path to Ouput file>")
DLPath = inputbox ( "Enter the Distribution List you want to list the members of:")
outPath = inputbox ( "Enter the path to the output file:")
elseif wscript.arguments.item ( 0) = "/?" Or wscript.arguments.item ( 0) = "-?" then
wscript.echo ( "Usage: distListMembers.vbs <Name of the Dist List> <Path to Ouput file>")
wscript.quit ( )
else
DLPath = wscript.arguments.item ( 0)
outPath = wscript.arguments.item ( 1)
end if
'====================================================================
'== Make sure we have some info
'====================================================================
if DLPath = "" or outPath = "" then
wscript.echo ( "There were not enough arguments passed to the script")
wscript.echo ( "Usage: distListMembers.vbs <Name of the Dist List> <Path to Ouput file>")
wscript.quit ( )
end if
strOrgUnit = ",cn=distContainer,ou=OrgUnit,o=Org"
strServer = "exchangeServer"
'====================================================================
'== Open the output file
'====================================================================
set outputFile = fso.createtextfile ( outPath)
adsDLPath = "LDAP://" & strServer & "/cn=" & DLPath & strOrgUnit
'====================================================================
'== bind to the DL and list the members
'====================================================================
set dlObj = getobject ( adsDLPath )
for each member in dlObj.Members
set usrObj = getobject ( member.adspath )
outputFile.writeline ( usrObj.uid & " " & usrObj.cn)
set usrObj = nothing
next
'====================================================================
'== clean up our references
'====================================================================
set dlObj = nothing
outputFile.close
set outputFile = nothing
set fso = nothing
wscript.quit ( )
'= Show Distribution List 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/).
'=
'====================================================================
'====================================================================
'==
'== distListMembers.vbs - a script that lists all the members of a
'== distribution list
'==
'====================================================================
set fso = createobject ( "Scripting.FileSystemObject")
'====================================================================
'== get the info required to run the script
'====================================================================
if wscript.arguments.count = 0 then
wscript.echo ( "Usage: distListMembers.vbs <Name of the Dist List> <Path to Ouput file>")
DLPath = inputbox ( "Enter the Distribution List you want to list the members of:")
outPath = inputbox ( "Enter the path to the output file:")
elseif wscript.arguments.item ( 0) = "/?" Or wscript.arguments.item ( 0) = "-?" then
wscript.echo ( "Usage: distListMembers.vbs <Name of the Dist List> <Path to Ouput file>")
wscript.quit ( )
else
DLPath = wscript.arguments.item ( 0)
outPath = wscript.arguments.item ( 1)
end if
'====================================================================
'== Make sure we have some info
'====================================================================
if DLPath = "" or outPath = "" then
wscript.echo ( "There were not enough arguments passed to the script")
wscript.echo ( "Usage: distListMembers.vbs <Name of the Dist List> <Path to Ouput file>")
wscript.quit ( )
end if
strOrgUnit = ",cn=distContainer,ou=OrgUnit,o=Org"
strServer = "exchangeServer"
'====================================================================
'== Open the output file
'====================================================================
set outputFile = fso.createtextfile ( outPath)
adsDLPath = "LDAP://" & strServer & "/cn=" & DLPath & strOrgUnit
'====================================================================
'== bind to the DL and list the members
'====================================================================
set dlObj = getobject ( adsDLPath )
for each member in dlObj.Members
set usrObj = getobject ( member.adspath )
outputFile.writeline ( usrObj.uid & " " & usrObj.cn)
set usrObj = nothing
next
'====================================================================
'== clean up our references
'====================================================================
set dlObj = nothing
outputFile.close
set outputFile = nothing
set fso = nothing
wscript.quit ( )
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.