<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>vbscriptblog.com &#187; groups</title>
	<atom:link href="http://vbscriptblog.com/category/vbscript/active-directory/groups/feed/" rel="self" type="application/rss+xml" />
	<link>http://vbscriptblog.com</link>
	<description>Scripting for Windows Sysadmins</description>
	<lastBuildDate>Mon, 16 Jan 2012 09:41:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Active Directory: VBscript to enumerate nested Active Directory groups from an Excel sheet</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-nested-active-directory-groups-from-an-excel-sheet/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-nested-active-directory-groups-from-an-excel-sheet/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 13:09:34 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[groups]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://vbscriptblog.com/?p=1277</guid>
		<description><![CDATA[Haven&#8217;t done much scripting lately&#8230;.. The script for today is made for Ananth Kumar. He asked me to make an extension to the &#8220;enumerate nested groups script&#8221; so that multiple nested groups can be enumerated based on an input file. I did choose Excel for the input file so that i could reuse previous code. [...]]]></description>
			<content:encoded><![CDATA[<p>Haven&#8217;t done much scripting lately&#8230;..<br />
The script for today is made for Ananth Kumar.<br />
He asked me to make an extension to the <a href="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-the-members-of-nested-groups-v2/" title=""enumerate nested groups script"">&#8220;enumerate nested groups script&#8221;</a> so that multiple nested groups can be enumerated based on an input file.<br />
I did choose Excel for the input file so that i could reuse previous code.</p>
<p>Follow the next steps to run the script (no admin rights needed):</p>
<ul>
<li>find the distinguished names of the nested groups (adsiedit.msc)</li>
<li>put them in an Excel sheet in the first column ans save the sheet as c:\temp\groups.xls</li>
<li>open your favorite text editor</li>
<li>copy and paste the script below into the editor (you can use the icons in the upper rights corner of the code)</li>
<li>save the script (for example c:\temp\enumeratenestedgroupsfromexcelsheet.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:\temp&#8221;</li>
<li>give &#8220;cscript enumeratenestedgroupsfromexcelsheet.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : enumeratenestedgroupsfromexcelsheet.vbs
' Description : script to enumerate nested Active Directory groups from an Excel sheet
' Author : dirk adamsky - deludi bv
' Version : 1.0
' Date : 04-10-2011

Set objExcel = CreateObject(&quot;Excel.Application&quot;)
Set objWorkbook = objExcel.Workbooks.Open(&quot;C:\temp\groups.xls&quot;)
intRow = 2
Do Until objExcel.Cells(intRow,1).Value = &quot;&quot;
strGroupDN = objExcel.Cells(intRow, 1).Value
If strGroupDN &lt;&gt; &quot;&quot; Then
wscript.echo strGroupDN
EnumNestedgroup &quot;LDAP://&quot; &amp; strGroupDN
End If
intRow = intRow + 1
Loop
objExcel.Quit
Set objWorkbook = Nothing
Set objExcel = Nothing

Function EnumNestedgroup(strGroupDN)
Set objGroup = GetObject(strGroupDN)
For Each objMember in objGroup.Members
If (LCase(objMember.Class) = &quot;group&quot;) Then
EnumNestedgroup objMember.AdsPath
Else
Wscript.Echo objGroup.cn &amp; &quot; ; &quot; &amp; objMember.DisplayName &amp; &quot; ; &quot; &amp; objMember.Mail
End If
Next
Set objGroup = Nothing
End Function
</pre>
<p>When you have a modified version or problems/questions that you want to share please post it at the comments below.</p>
<p>Happy scripting.</p>
<p>Dirk Adamsky</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Factive-directory%2Fgroups%2Factive-directory-vbscript-to-enumerate-nested-active-directory-groups-from-an-excel-sheet%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-nested-active-directory-groups-from-an-excel-sheet/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-nested-active-directory-groups-from-an-excel-sheet/"  data-text="Active Directory: VBscript to enumerate nested Active Directory groups from an Excel sheet" data-count="horizontal" data-via="dirkadamsky">Tweet</a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-nested-active-directory-groups-from-an-excel-sheet/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-nested-active-directory-groups-from-an-excel-sheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBscript: VBscript to enumerate all groups and their members from a specific Active Directory OU</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/groups/vbscript-vbscript-to-enumerate-all-groups-and-their-members-from-a-specific-active-directory-ou/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/groups/vbscript-vbscript-to-enumerate-all-groups-and-their-members-from-a-specific-active-directory-ou/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 12:43:14 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[groups]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[members]]></category>
		<category><![CDATA[memberships]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=1120</guid>
		<description><![CDATA[Today&#8217;s script is made for Tyrone. His question was a script that enumerates all groups and their members from a given OU. I already had a script that enumerates the members of an OU. I also had a script that enumerates the members of a nested group (uses recursion). The 2 scripts combined are the [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s script is made for <a href="http://vbscriptblog.com/vbscript/active-directory/vbscript-to-enumerate-the-members-of-nested-groups/">Tyrone</a>.</p>
<p>His question was a script that enumerates all groups and their members from a given OU.<br />
I already had a script that enumerates the members of an OU.<br />
I also had a script that <a href="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-the-members-of-nested-groups-v2/">enumerates the members of a nested group</a> (uses <a href="http://en.wikipedia.org/wiki/Recursion">recursion</a>).<br />
The 2 scripts combined are the solution for Tyrone.</p>
<p>Follow the next steps to run the script (no admin rights needed):</p>
<p>* open your favorite text editor<br />
* copy and paste the script into the editor<br />
* change the OU distinguished name (in line 7) into your OU <a href="http://msdn.microsoft.com/en-us/library/aa366101%28v=vs.85%29.aspx">distinguished name</a><br />
* save the script (for example c:\temp\EnumerateGroupsInOu.vbs)<br />
* open a command prompt<br />
* go to &#8220;c:\temp&#8221;<br />
* give &#8220;cscript EnumerateGroupsInOu.vbs&#8221; (without quotes) and enter</p>
<p>You can also dump the output to a file:</p>
<p>* give &#8220;cscript EnumerateGroupsInOu.vbs > EnumerateGroupsInOu.txt&#8221; (without quotes) and enter</p>
<p>To get that file into Excel:</p>
<p>* open Excel<br />
* go to Menu=>Open File<br />
* change file type to &#8220;all&#8221;<br />
* chose EnumerateGroupsInOu.txt<br />
* chose &#8220;;&#8221; as separator character</p>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : EnumerateGroupsInOu.vbs
' Description : script to enumerate all groups and their members from a specific Active Directory OU
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 01-06-2011

Set objOU = GetObject(&quot;LDAP://OU=test,DC=test,DC=org&quot;)
	For Each objMember in objOU
		If (LCase(objMember.Class) = &quot;group&quot;) Then
			EnumNestedgroup objMember.AdsPath
		End If
	Next
Set objOU = Nothing

Function EnumNestedgroup(strGroupDN)
	Set objGroup = GetObject(strGroupDN)
	For Each objMember in objGroup.Members
		If (LCase(objMember.Class) = &quot;group&quot;) Then
			wscript.echo objMember.AdsPath
			EnumNestedgroup objMember.AdsPath
		Else
			Wscript.Echo objGroup.Name &amp; &quot; ; &quot; &amp; objMember.DisplayName &amp; &quot; ; &quot; &amp; objMember.Mail &amp;_
			&quot; ; &quot; &amp; objMember.Department &amp;  &quot; ; &quot; &amp;	objMember.Company &amp; &quot; ;  &quot; &amp; objMember.Title
		End If
	Next
	Set objGroup = Nothing
End Function
</pre>
<p>When you have problems/questions with the script please post a reply.</p>
<p>Happy scripting.</p>
<p>Best regards,</p>
<p>Dirk Adamsky</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Factive-directory%2Fgroups%2Fvbscript-vbscript-to-enumerate-all-groups-and-their-members-from-a-specific-active-directory-ou%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/active-directory/groups/vbscript-vbscript-to-enumerate-all-groups-and-their-members-from-a-specific-active-directory-ou/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/active-directory/groups/vbscript-vbscript-to-enumerate-all-groups-and-their-members-from-a-specific-active-directory-ou/"  data-text="VBscript: VBscript to enumerate all groups and their members from a specific Active Directory OU" data-count="horizontal" data-via="dirkadamsky">Tweet</a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/active-directory/groups/vbscript-vbscript-to-enumerate-all-groups-and-their-members-from-a-specific-active-directory-ou/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/groups/vbscript-vbscript-to-enumerate-all-groups-and-their-members-from-a-specific-active-directory-ou/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Active Directory: VBscript to enumerate all empty groups</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-all-empty-groups/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-all-empty-groups/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 12:11:13 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[groups]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[distribution group]]></category>
		<category><![CDATA[empty groups]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[memberships]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=443</guid>
		<description><![CDATA[For most system administrators cleaning up Active Directory is not their favorite thing. This script helps you by enumerating all empty groups, so you can remove them (manually). Follow the next steps to run the script (no admin rights needed): * open your favorite text editor * copy and paste the script into the editor [...]]]></description>
			<content:encoded><![CDATA[<p>For most system administrators cleaning up Active Directory is not their favorite thing.<br />
This script helps you by enumerating all empty groups, so you can remove them (manually).</p>
<p>Follow the next steps to run the script (no admin rights needed):</p>
<p>* open your favorite text editor<br />
* copy and paste the script into the editor<br />
* save the script (for example c:\temp\emptygroups.vbs)<br />
* open a command prompt<br />
* go to &#8220;c:\temp&#8221;<br />
* give &#8220;cscript emptygroups.vbs&#8221; (without quotes) and enter</p>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : emptygroups.vbs
' Description : script to enumerate all empty groups
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 18-03-2010
' Level : intermediate

Set objCommand = CreateObject(&quot;ADODB.Command&quot;)
Set objConnection = CreateObject(&quot;ADODB.Connection&quot;)
objConnection.Provider = &quot;ADsDSOObject&quot;
objConnection.Open &quot;Active Directory Provider&quot;
objCommand.ActiveConnection = objConnection

Set objRootDSE = GetObject(&quot;LDAP://RootDSE&quot;)
strBase = &quot;&lt;LDAP://&quot; &amp; objRootDSE.Get(&quot;defaultNamingContext&quot;) &amp; &quot;&gt;&quot;
Set objRootDSE = Nothing

strFilter = &quot;(&amp;(objectCategory=group)(!member=*))&quot;
strAttributes = &quot;name&quot;
strQuery = strBase &amp; &quot;;&quot; &amp; strFilter &amp; &quot;;&quot; &amp; strAttributes &amp; &quot;;subtree&quot;
objCommand.CommandText = strQuery
objCommand.Properties(&quot;Page Size&quot;) = 100
objCommand.Properties(&quot;Timeout&quot;) = 30
objCommand.Properties(&quot;Cache Results&quot;) = False

Set objRecordSet = objCommand.Execute
Do Until objRecordSet.EOF
	Wscript.Echo objRecordSet.Fields(&quot;name&quot;).Value
	objRecordSet.MoveNext
Loop

objRecordSet.Close
objConnection.Close

Set objRecordSet = Nothing
Set objConnection = Nothing
Set objCommand = Nothing
</pre>
<p>When you have problems/questions please post a reply, you can also rate the script.</p>
<p>Happy scripting.</p>
<p>Best regards,</p>
<p>Dirk Adamsky &#8211; Deludi BV</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Factive-directory%2Fgroups%2Factive-directory-vbscript-to-enumerate-all-empty-groups%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-all-empty-groups/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-all-empty-groups/"  data-text="Active Directory: VBscript to enumerate all empty groups" data-count="horizontal" data-via="dirkadamsky">Tweet</a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-all-empty-groups/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-all-empty-groups/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Active Directory: VBscript to show all groups with multiple smtp addresses</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-show-all-groups-with-multiple-smtp-addresses/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-show-all-groups-with-multiple-smtp-addresses/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 08:06:08 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[groups]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[distribution group]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[exchange]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[smtp address]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=345</guid>
		<description><![CDATA[This script is a mutation of yesterday&#8217;s script. It searches Active Directory for mail enabled groups with multiple smtp addresses. By changing the treshold value (i) in line number 39 you can broaden or narrow your searches. Follow the next steps to run the script (no admin rights needed): * open your favorite text editor [...]]]></description>
			<content:encoded><![CDATA[<p>This script is a mutation of <a href="http://deludi.nl/blog/vbscript/active-directory/email/active-directory-vbscript-to-show-all-users-with-multiple-smtp-addresses/">yesterday&#8217;s script.</a><br />
It searches Active Directory for mail enabled groups with multiple smtp addresses.<br />
By changing the treshold value (i) in line number 39 you can broaden or narrow your searches.</p>
<p>Follow the next steps to run the script (no admin rights needed):</p>
<p>* open your favorite text editor<br />
* copy and paste the script into the editor<br />
* save the script (for example c:tempshowgroupswithmultiplesmtp.vbs)<br />
* open a command prompt<br />
* go to &#8220;c:temp&#8221;<br />
* give &#8220;cscript showgroupswithmultiplesmtp.vbs&#8221; (without quotes) and enter</p>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : showgroupswithmultiplesmtp.vbs
' Description : script to show all groups with multiple smtp addresses
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 23-02-2010
' Level : intermediate

Set adoCommand = CreateObject(&quot;ADODB.Command&quot;)
Set adoConnection = CreateObject(&quot;ADODB.Connection&quot;)
adoConnection.Provider = &quot;ADsDSOObject&quot;
adoConnection.Open &quot;Active Directory Provider&quot;
adoCommand.ActiveConnection = adoConnection

Set objRootDSE = GetObject(&quot;LDAP://RootDSE&quot;)
strDNSDomain = objRootDSE.Get(&quot;defaultNamingContext&quot;)
strBase = &quot;&lt;LDAP://&quot; &amp; strDNSDomain &amp; &quot;&gt;&quot;

strFilter = &quot;(&amp;(objectCategory=group)(mail=*))&quot;
strAttributes = &quot;distinguishedName&quot;

strQuery = strBase &amp; &quot;;&quot; &amp; strFilter &amp; &quot;;&quot; &amp; strAttributes &amp; &quot;;subtree&quot;
adoCommand.CommandText = strQuery
adoCommand.Properties(&quot;Page Size&quot;) = 100
adoCommand.Properties(&quot;Timeout&quot;) = 30
adoCommand.Properties(&quot;Cache Results&quot;) = False

Set adoRecordset = adoCommand.Execute

Do Until adoRecordset.EOF
	On Error Resume Next
	Set objGroup = GetObject (&quot;LDAP://&quot; &amp; adoRecordset.Fields(&quot;distinguishedName&quot;).Value)
	arrProxy = objGroup.GetEx(&quot;proxyAddresses&quot;)
	i = 0
	For Each strMailAddress in arrProxy
		If Lcase(Left(strMailAddress,5))= &quot;smtp:&quot; Then
			i = i + 1
		End If
	Next
	If i &gt;= 2 Then
		strAllMailAddresses = &quot;&quot;
		For Each strMailAddress in arrProxy
			If Lcase(Left(strMailAddress,5))= &quot;smtp:&quot; Then
				strAllMailAddresses = strAllMailAddresses &amp; &quot; ; &quot;  &amp; strMailAddress
			End If
		Next
		Wscript.Echo objGroup.DisplayName &amp; strAllMailAddresses
	End If
	Set objGroup = Nothing
	adoRecordset.MoveNext
Loop

adoRecordset.Close
adoConnection.Close

Set adoRecordset = Nothing
Set objRootDSE = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing
</pre>
<p>When you have problems/questions please post a reply.<br />
I also added a rating system yesterday, thank you in advance for your reaction.</p>
<p>Happy scripting.</p>
<p>Best regards,</p>
<p>Dirk Adamsky &#8211; Deludi BV</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Factive-directory%2Fgroups%2Factive-directory-vbscript-to-show-all-groups-with-multiple-smtp-addresses%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-show-all-groups-with-multiple-smtp-addresses/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-show-all-groups-with-multiple-smtp-addresses/"  data-text="Active Directory: VBscript to show all groups with multiple smtp addresses" data-count="horizontal" data-via="dirkadamsky">Tweet</a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-show-all-groups-with-multiple-smtp-addresses/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-show-all-groups-with-multiple-smtp-addresses/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Active Directory: VBscript to enumerate the members of nested groups V2</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-the-members-of-nested-groups-v2/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-the-members-of-nested-groups-v2/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 09:04:19 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[groups]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[distribution group]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[members]]></category>
		<category><![CDATA[memberships]]></category>
		<category><![CDATA[nested group]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[smtp address]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=245</guid>
		<description><![CDATA[A couple of weeks ago I posted the enumeratenestedgroup script. Last friday (while working at another script) I thought: this can be done better/more efficient. What I have done is a rewrite of the script, it now contains 50% less code. This is mainly because the recursion is implemented better. When you are not familiar [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago I posted the <a href="http://deludi.nl/blog/vbscript/active-directory/vbscript-to-enumerate-the-members-of-nested-groups/">enumeratenestedgroup</a> script.<br />
Last friday (while working at another script) I thought: this can be done better/more efficient.<br />
What I have done is a rewrite of the script, it now contains 50% less code.<br />
This is mainly because the recursion is implemented better.<br />
When you are not familiar with recursion: <a href="http://en.wikipedia.org/wiki/Recursion">here&#8217;s a extensive wikipedia article</a>.<br />
You can easily modify the script with extra user attributes, counters, etc.<br />
Here you can find some mutations of the enumerate nested group script:</p>
<ul>
<li><a href="http://vbscriptblog.com/vbscript/active-directory/citrix/active-directory-vbscript-to-enumerate-the-lastlogon-of-all-users-of-a-nested-group/">script to enumerate the lastlogon of all users of a nested group</a></li>
<li><a href="http://vbscriptblog.com/vbscript/active-directory/citrix/active-directory-vbscript-to-enumerate-the-citrix-tokens-of-a-nested-group/">script to enumerate the citrix tokens of a nested group</a></li>
</ul>
<p>What the script does:</p>
<ul>
<li>fill a variable with the group distinguished name</li>
<li>call the function EnumNestedgroup</li>
<li>the function checks whether the member is a group or a user</li>
<li>when the member is a user the displayname and smtp address are echoed on the screen</li>
<li>when the member is a group the group distinguished name is echoed and the function is called again</li>
<li>this loop continues untill the last member is enumerated</li>
</ul>
<p>Follow the next steps to run the script  (no admin rights needed):</p>
<ul>
<li>find the distinguished name of the nested group (adsiedit.msc)</li>
<li>open your favorite text editor</li>
<li>copy and paste the script into the editor</li>
<li>change the distinguished name</li>
<li>save the script (for example c:\tempenumeratenestedgroup.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:\temp&#8221;</li>
<li>give &#8220;cscript enumeratenestedgroup.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : enumeratenestedgroup.vbs
' Description : script to enumerate the members of a nested group
' Author : dirk adamsky - deludi bv
' Version : 2.2 replaced the subroutine statement with a function statement
' Date : 07-06-2011

strTargetGroupDN = &quot;LDAP://CN=testgroup,OU=groups,DC=test,DC=org&quot;
EnumNestedgroup strTargetGroupDN
Function EnumNestedgroup(strGroupDN)
	Set objGroup = GetObject(strGroupDN)
	For Each objMember in objGroup.Members
		If (LCase(objMember.Class) = &quot;group&quot;) Then
			wscript.echo objMember.AdsPath
			EnumNestedgroup objMember.AdsPath
		Else
			Wscript.Echo objMember.DisplayName &amp; &quot; ; &quot; &amp; objMember.Mail
		End If
	Next
	Set objGroup = Nothing
End Function
</pre>
<p>When you have a modified version or problems/questions that you want to share please post it at the comments below.</p>
<p>Happy scripting.</p>
<p>Dirk Adamsky</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Factive-directory%2Fgroups%2Factive-directory-vbscript-to-enumerate-the-members-of-nested-groups-v2%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-the-members-of-nested-groups-v2/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-the-members-of-nested-groups-v2/"  data-text="Active Directory: VBscript to enumerate the members of nested groups V2" data-count="horizontal" data-via="dirkadamsky">Tweet</a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-the-members-of-nested-groups-v2/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-the-members-of-nested-groups-v2/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>Active Directory: VBscript to enumerate all active directory distributiongroups with manager</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-all-distributiongroups-with-manager/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-all-distributiongroups-with-manager/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 08:47:35 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[groups]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[adsi]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[distribution group]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[managedBy]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[smtp address]]></category>
		<category><![CDATA[user]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=191</guid>
		<description><![CDATA[This script enumerates all active directory distribution groups with a manager. It starts with an ado query for the distinguished name of all group objects with an smtp address (accomplished by checking the mail property in the ado filter). For each group a group object is created, the displayname, mail attribute and managedBy attribute of [...]]]></description>
			<content:encoded><![CDATA[<p>This script enumerates all active directory distribution groups with a manager.<br />
It starts with an ado query for the distinguished name of all group objects with an smtp address (accomplished by checking the mail property in the ado filter).<br />
For each group a group object is created, the displayname, mail attribute and managedBy attribute of the group are displayed.</p>
<p>Follow the next steps to make and run the script (no admin rights needed):</p>
<ul>
<li>open your favorite text editor (mine is notepad++)</li>
<li>copy and paste the script into the editor (delete the line numbers)</li>
<li>save the script (for example c:tempdistributiongroupswithmanager.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:temp&#8221;</li>
<li>give &#8220;cscript distributiongroupswithmanager.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>When you want to save the output in a textfile give:</p>
<p>&#8220;cscript distributiongroupswithmanager.vbs > distributiongroupswithmanager.txt&#8221; (without quotes) and enter</p>
<p>The script: </p>
<pre class="brush: vb; title: ; notranslate">
' Name : distributiongroupswithmanager.vbs
' Description : script to enumerate all distributiongroups with manager
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 01-02-2010
' Level : intermediate

Set adoCommand = CreateObject(&quot;ADODB.Command&quot;)
Set adoConnection = CreateObject(&quot;ADODB.Connection&quot;)
adoConnection.Provider = &quot;ADsDSOObject&quot;
adoConnection.Open &quot;Active Directory Provider&quot;
adoCommand.ActiveConnection = adoConnection

Set objRootDSE = GetObject(&quot;LDAP://RootDSE&quot;)
strDNSDomain = objRootDSE.Get(&quot;defaultNamingContext&quot;)
strBase = &quot;&lt;LDAP://&quot; &amp; strDNSDomain &amp; &quot;&gt;&quot;
strFilter = &quot;(&amp;(objectCategory=group)(mail=*))&quot;
strAttributes = &quot;distinguishedName&quot;

strQuery = strBase &amp; &quot;;&quot; &amp; strFilter &amp; &quot;;&quot; &amp; strAttributes &amp; &quot;;subtree&quot;
adoCommand.CommandText = strQuery
adoCommand.Properties(&quot;Page Size&quot;) = 100
adoCommand.Properties(&quot;Timeout&quot;) = 30
adoCommand.Properties(&quot;Cache Results&quot;) = False

Set objRecordset = adoCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
	On Error Resume Next
	Set objGroup = GetObject(&quot;LDAP://&quot; &amp; objRecordSet.Fields(&quot;distinguishedName&quot;).Value)
	Wscript.Echo objGroup.DisplayName &amp; &quot; ; &quot; &amp; objGroup.Mail &amp; &quot; ; &quot; &amp; objGroup.managedBy
	Set objGroup = Nothing
	objRecordSet.MoveNext
Loop

Set objRecordset = Nothing
Set objRootDSE = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing
</pre>
<p>When you have questions or problems with the script please drop a comment.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Factive-directory%2Fgroups%2Factive-directory-vbscript-to-enumerate-all-distributiongroups-with-manager%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-all-distributiongroups-with-manager/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-all-distributiongroups-with-manager/"  data-text="Active Directory: VBscript to enumerate all active directory distributiongroups with manager" data-count="horizontal" data-via="dirkadamsky">Tweet</a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-all-distributiongroups-with-manager/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-enumerate-all-distributiongroups-with-manager/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Active Directory: Simple VBscript to enumerate group members</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-simple-vbscript-to-enumerate-group-members/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-simple-vbscript-to-enumerate-group-members/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 07:56:21 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[groups]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[adsi]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[memberOf]]></category>
		<category><![CDATA[memberships]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=174</guid>
		<description><![CDATA[Scripting sometimes seems tough to learn. To help you I have made a couple of starter scripts. This starter script is only 5 lines of code. The script lists all members of a group. Follow the next steps to make and run the script (no admin rights needed): open your favorite text editor (mine is [...]]]></description>
			<content:encoded><![CDATA[<p>Scripting sometimes seems tough to learn.<br />
To help you I have made a couple of starter scripts.</p>
<p>This starter script is only 5 lines of code.<br />
The script lists all members of a group.</p>
<p>Follow the next steps to make and run the script (no admin rights needed):</p>
<ul>
<li>open your favorite text editor (mine is notepad++)</li>
<li>copy and paste the script into the editor (delete the line numbers)</li>
<li>open adsiedit as a user (start=>run=>adsiedit.msc)</li>
<li>browse to the group</li>
<li>rightclick the group and choose properties</li>
<li>select the distinguishedname attribute</li>
<li>copy the value of the distinguishedname attribute</li>
<li>change the value of the distinguishedname attribute in the script</li>
<li>save the script (for example c:tempenumerategroup.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:temp&#8221;</li>
<li>give &#8220;cscript enumerategroup.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>When you want to save the output in a textfile give:</p>
<p>&#8220;cscript enumerategroup.vbs > groupname.txt&#8221; (without quotes) and enter</p>
<p>The script: </p>
<pre class="brush: vb; title: ; notranslate">
' Name : enumerategroup.vbs
' Description : script to enumerate group members
' Author : dirk adamsky - deludi bv
' Version : 1.10 corrected with the input of Ciobotario
' Date : 12-04-2011
' Level : beginner

Set objGroup = GetObject(&quot;LDAP://CN=test,OU=test,DC=test,DC=org&quot;)	' create the group object
For Each Member in objGroup.Members	' for  each member of the group
	WScript.echo Member.cn &amp; &quot; ; &quot; &amp; Member.displayName	' echo the common name and displayname
Next
Set objGroup = Nothing	' delete the group object and clear memory
</pre>
<p>When you have questions or problems with the script please drop a comment.</p>
<p>Happy scripting.</p>
<p>Best regards,</p>
<p>Dirk Adamsky &#8211; Deludi BV</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Factive-directory%2Fgroups%2Factive-directory-simple-vbscript-to-enumerate-group-members%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-simple-vbscript-to-enumerate-group-members/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-simple-vbscript-to-enumerate-group-members/"  data-text="Active Directory: Simple VBscript to enumerate group members" data-count="horizontal" data-via="dirkadamsky">Tweet</a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-simple-vbscript-to-enumerate-group-members/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-simple-vbscript-to-enumerate-group-members/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Active Directory: VBscript to copy the members of a nested group to another group</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-copy-the-members-of-a-nested-group-to-another-group-2/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-copy-the-members-of-a-nested-group-to-another-group-2/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 13:48:24 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[groups]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=170</guid>
		<description><![CDATA[This script copies the members of a nested group to another group. Follow the next steps to run the script (admin rights needed): open your favorite text editor copy and paste the script into the editor change the distinguished name of the source group to your source group name change the distinguished name of the [...]]]></description>
			<content:encoded><![CDATA[<p>This script copies the members of a nested group to another group.</p>
<p>Follow the next steps to run the script  (admin rights needed):</p>
<ul>
<li>open your favorite text editor</li>
<li>copy and paste the script into the editor</li>
<li>change the distinguished name of the source group to your source group name</li>
<li>change the distinguished name of the target group to your target group name</li>
<li>save the script (for example c:tempcopynestedgroupuserstogroup.vbs)</li>
<li>open a command prompt with administrative rights</li>
<li>go to &#8220;c:temp&#8221;</li>
<li>give &#8220;cscript copynestedgroupuserstogroup.vbs&#8221; (without quotes) and enter</li>
<li>give &#8220;ok&#8221;</li>
</ul>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : copynestedgroupuserstogroup.vbs
' Description : script to copy the members of a nested group to another group
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 28-01-2010

Set objSourceGroup = GetObject(&quot;LDAP://CN=sourcegroupname,OU=test,DC=test,DC=org&quot;)
For Each objMember in objSourceGroup.Members
	If (LCase(objMember.Class) = &quot;group&quot;) Then
		Set objSubGroup = GetObject(objMember.AdsPath)
		Call EnumNestedgroup(objSubGroup)
		Set objSubGroup = Nothing
	Else
		On Error Resume Next
		Set objTargetGroup = GetObject(&quot;LDAP://CN=targetgroupname,OU=test,DC=test,DC=org&quot;)
		objTargetGroup.Add(objMember.ADsPath)
		objTargetGroup.Setinfo
		Set objTargetGroup = Nothing
	End If

Next
Set objSourceGroup = Nothing

Sub EnumNestedGroup(objNestedGroup)
    For Each objSubMember In objNestedGroup.Members
        If (LCase(objSubMember.Class) = &quot;group&quot;) Then
            Set objSubNestedGroup = GetObject(objSubMember.AdsPath)
			Call EnumNestedGroup(objSubNestedGroup)
			Set objSubNestedGroup = Nothing
		Else
			On Error Resume Next
			Set objTargetGroup = GetObject(&quot;LDAP://CN=targetgroupname,OU=test,DC=test,DC=org&quot;)
			objTargetGroup.Add(objSubMember.ADsPath)
			objTargetGroup.Setinfo
			Set objTargetGroup = Nothing
		End If
    Next
End Sub
</pre>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Factive-directory%2Fgroups%2Factive-directory-vbscript-to-copy-the-members-of-a-nested-group-to-another-group-2%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-copy-the-members-of-a-nested-group-to-another-group-2/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-copy-the-members-of-a-nested-group-to-another-group-2/"  data-text="Active Directory: VBscript to copy the members of a nested group to another group" data-count="horizontal" data-via="dirkadamsky">Tweet</a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-copy-the-members-of-a-nested-group-to-another-group-2/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/groups/active-directory-vbscript-to-copy-the-members-of-a-nested-group-to-another-group-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Active Directory: VBScript to enumerate all groups a user is memberOf</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/active-directory-vbscript-to-enumerate-all-groups-a-user-is-memberof/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/active-directory-vbscript-to-enumerate-all-groups-a-user-is-memberof/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 14:04:47 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[active directory]]></category>
		<category><![CDATA[groups]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[memberOf]]></category>
		<category><![CDATA[smtp address]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=78</guid>
		<description><![CDATA[This script enumerates all group memberships of a user. What the script does: ask for the smtp address of the user (inputbox) the function GetDN gets the distinguished name create the user object check is there are groups that the user is memberOf enumerate the group DN&#8217;s Follow the next steps to run the script [...]]]></description>
			<content:encoded><![CDATA[<p>This script enumerates all group memberships of a user.</p>
<p>What the script does:</p>
<ul>
<li>ask for the smtp address of the user (inputbox)</li>
<li>the function GetDN gets the distinguished name</li>
<li>create the user object</li>
<li>check is there are groups that the user is memberOf</li>
<li>enumerate the group DN&#8217;s</li>
</ul>
<p>Follow the next steps to run the script  (no admin rights needed):</p>
<ul>
<li>find the smtp address of the user (outlook/aduc)</li>
<li>open your favorite text editor</li>
<li>copy and paste the script into the editor</li>
<li>save the script (for example c:tempenumerategroupsfromuser.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:temp&#8221;</li>
<li>give &#8220;cscript enumerategroupsfromuser.vbs&#8221; (without quotes) and enter</li>
<li>in the input box fill in the smtp address of the user</li>
<li>give &#8220;ok&#8221;</li>
</ul>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : enumerategroupsfromuser.vbs
' Description : script to enumerate all groups a user is memberOf
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 21-01-2010

strChangeUser = InputBox(&quot;Fill in the smtp address of the user&quot;)
strUserDN = GetDN(strChangeUser)

Set objUser = GetObject(&quot;LDAP://&quot; &amp; strUserDN)
If Ubound(objUser.memberOf) &lt;&gt; &quot;&quot; Then
    objGroups = objUser.GetEx(&quot;memberOf&quot;)
    For Each objGroup in objGroups
        Wscript.Echo objGroup
    Next
End If
Set objUser = Nothing

Function GetDN(strMail)

    Set adoCommand = CreateObject(&quot;ADODB.Command&quot;)
    Set adoConnection = CreateObject(&quot;ADODB.Connection&quot;)
    adoConnection.Provider = &quot;ADsDSOObject&quot;
    adoConnection.Open &quot;Active Directory Provider&quot;
    adoCommand.ActiveConnection = adoConnection

    ' Search entire Active Directory domain.
    Set objRootDSE = GetObject(&quot;LDAP://RootDSE&quot;)
    strDNSDomain = objRootDSE.Get(&quot;defaultNamingContext&quot;)
    strBase = &quot;&lt;LDAP://&quot; &amp; strDNSDomain &amp; &quot;&gt;&quot;

    ' Filter on user objects.
    strFilter = &quot;(&amp;(objectCategory=person)(objectClass=user)(mail=&quot; &amp;  strMail &amp; &quot;))&quot;

    ' Comma delimited list of attribute values to retrieve.
    strAttributes = &quot;distinguishedName&quot;

    ' Construct the LDAP syntax query.
    strQuery = strBase &amp; &quot;;&quot; &amp; strFilter &amp; &quot;;&quot; &amp; strAttributes &amp; &quot;;subtree&quot;
    adoCommand.CommandText = strQuery
    adoCommand.Properties(&quot;Page Size&quot;) = 100
    adoCommand.Properties(&quot;Timeout&quot;) = 30
    adoCommand.Properties(&quot;Cache Results&quot;) = False

    ' Run the query.
    Set adoRecordset = adoCommand.Execute
    GetDN = adoRecordset.Fields(&quot;distinguishedName&quot;).Value
    ' Clean up.
    adoRecordset.Close
    adoConnection.Close

    Set adoRecordset = Nothing
    Set objRootDSE = Nothing
    Set adoConnection = Nothing
    Set adoCommand = Nothing

End Function
</pre>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Factive-directory%2Factive-directory-vbscript-to-enumerate-all-groups-a-user-is-memberof%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/active-directory/active-directory-vbscript-to-enumerate-all-groups-a-user-is-memberof/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/active-directory/active-directory-vbscript-to-enumerate-all-groups-a-user-is-memberof/"  data-text="Active Directory: VBScript to enumerate all groups a user is memberOf" data-count="horizontal" data-via="dirkadamsky">Tweet</a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/active-directory/active-directory-vbscript-to-enumerate-all-groups-a-user-is-memberof/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/active-directory-vbscript-to-enumerate-all-groups-a-user-is-memberof/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Active Directory: VBScript to change the groups from a user based on an example user</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/active-directory-vbscript-to-change-the-groups-from-a-user-based-on-an-example-user/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/active-directory-vbscript-to-change-the-groups-from-a-user-based-on-an-example-user/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 16:11:10 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[active directory]]></category>
		<category><![CDATA[groups]]></category>
		<category><![CDATA[example user]]></category>
		<category><![CDATA[memberOf]]></category>
		<category><![CDATA[memberships]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=48</guid>
		<description><![CDATA[VBScript to change the groups from a user based on an example user]]></description>
			<content:encoded><![CDATA[<p>In large organisations users frequently change departments.<br />
As a consequence the group memberships of the user have to change also.<br />
Often this is achieved by using an example user.<br />
When the example user has a lot of memberships this can be a time consuming task.<br />
This script asks for the smtp address of the user that has to be changed,<br />
then for the smtp address of the example user.<br />
The function GetDN does a lookup in Active Directory for the distinguished name<br />
of both users.<br />
Then the old group memberships of the user are removed.<br />
At last the group memberships of the example user are added.</p>
<p>Follow the next steps to run the script  (admin rights needed):</p>
<ul>
<li>open your favorite text editor</li>
<li>copy and paste the script into the editor</li>
<li>save the script (for example c:tempchangegroupmemberships.vbs)</li>
<li>open a command prompt with administrative rights</li>
<li>go to &#8220;c:temp&#8221;</li>
<li>give &#8220;cscript changegroupmemberships.vbs&#8221; (without quotes) and enter</li>
<li>in the input box fill in the smtp address of the user that has to be changed</li>
<li>in the next input box fill in the smtp address of the example user</li>
<li>give &#8220;ok&#8221;</li>
</ul>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : changegroupmemberships.vbs
' Description : script to change group memberships based on example user
' Author : dirk adamsky - deludi bv
' Version : 1.01
' Date : 16-01-2010

strChangeUser = InputBox(&quot;Fill in the SMTP address of the user that has to be changed&quot;)
strVoorbeeldUser = InputBox(&quot;Fill in the SMTP address of the example user&quot;)
strChangeUserDN = GetDN(strChangeUser)
strVoorbeeldUserDN = GetDN(strVoorbeeldUser)
Removegroups strChangeUserDN
Addgroups strChangeUserDN, strVoorbeeldUserDN

Function GetDN(strMail)

    Set adoCommand = CreateObject(&quot;ADODB.Command&quot;)
    Set adoConnection = CreateObject(&quot;ADODB.Connection&quot;)
    adoConnection.Provider = &quot;ADsDSOObject&quot;
    adoConnection.Open &quot;Active Directory Provider&quot;
    adoCommand.ActiveConnection = adoConnection

    ' Search entire Active Directory domain.
    Set objRootDSE = GetObject(&quot;LDAP://RootDSE&quot;)
    strDNSDomain = objRootDSE.Get(&quot;defaultNamingContext&quot;)
    strBase = &quot;&lt;LDAP://&quot; &amp; strDNSDomain &amp; &quot;&gt;&quot;

    ' Filter on user objects.
    strFilter = &quot;(&amp;(objectCategory=person)(objectClass=user)(mail=&quot; &amp;  strMail &amp; &quot;))&quot;

    ' Comma delimited list of attribute values to retrieve.
    strAttributes = &quot;distinguishedName&quot;

    ' Construct the LDAP syntax query.
    strQuery = strBase &amp; &quot;;&quot; &amp; strFilter &amp; &quot;;&quot; &amp; strAttributes &amp; &quot;;subtree&quot;
    adoCommand.CommandText = strQuery
    adoCommand.Properties(&quot;Page Size&quot;) = 100
    adoCommand.Properties(&quot;Timeout&quot;) = 30
    adoCommand.Properties(&quot;Cache Results&quot;) = False

    ' Run the query.
    Set adoRecordset = adoCommand.Execute
    GetDN = adoRecordset.Fields(&quot;distinguishedName&quot;).Value
    ' Clean up.
    adoRecordset.Close
    adoConnection.Close

    Set adoRecordset = Nothing
    Set objRootDSE = Nothing
    Set adoConnection = Nothing
    Set adoCommand = Nothing

End Function

Sub Removegroups(strUserDN)
    Const ADS_PROPERTY_DELETE = 4
    Set objUser = GetObject(&quot;LDAP://&quot; &amp; strUserDN)
    If Ubound(objUser.memberOf) &lt;&gt; &quot;&quot; Then
        arrMemberOf = objUser.GetEx(&quot;memberOf&quot;)
        For Each Group in arrMemberOf
            Set objGroup = GetObject(&quot;LDAP://&quot; &amp; Group)
            objGroup.PutEx ADS_PROPERTY_DELETE, &quot;member&quot;, Array(strUserDN)
            objGroup.SetInfo
            Set objGroup = Nothing
        Next
    End If
End Sub

Sub Addgroups(strChangeDN,strVBDN)
    On Error Resume Next
    Set objUser = GetObject(&quot;LDAP://&quot; &amp; strVBDN)
    arrMemberOf = objUser.GetEx(&quot;memberOf&quot;)
    For Each Group in arrMemberOf
        Set objGroup = GetObject(&quot;LDAP://&quot; &amp; Group)
        objGroup.Add(&quot;LDAP://&quot; &amp; strChangeDN)
        objGroup.SetInfo
        Set objGroup = Nothing
    Next
End Sub
</pre>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fvbscriptblog.com%2Fvbscript%2Factive-directory%2Factive-directory-vbscript-to-change-the-groups-from-a-user-based-on-an-example-user%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://vbscriptblog.com/vbscript/active-directory/active-directory-vbscript-to-change-the-groups-from-a-user-based-on-an-example-user/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://vbscriptblog.com/vbscript/active-directory/active-directory-vbscript-to-change-the-groups-from-a-user-based-on-an-example-user/"  data-text="Active Directory: VBScript to change the groups from a user based on an example user" data-count="horizontal" data-via="dirkadamsky">Tweet</a>
			</div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://vbscriptblog.com/vbscript/active-directory/active-directory-vbscript-to-change-the-groups-from-a-user-based-on-an-example-user/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/active-directory-vbscript-to-change-the-groups-from-a-user-based-on-an-example-user/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

