<?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; ou</title>
	<atom:link href="http://vbscriptblog.com/category/vbscript/active-directory/ou/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 all Active Directory users sorted by OU</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/ou/active-directory-vbscript-to-enumerate-all-active-directory-users-sorted-by-ou/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/ou/active-directory-vbscript-to-enumerate-all-active-directory-users-sorted-by-ou/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 10:53:24 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[ou]]></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[filesystem object]]></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=1288</guid>
		<description><![CDATA[Austin Murtha sent me an email with a script question. His problem was a script that enumerates users and their OU&#8217;s. I have created the script below to help him. What the script does: create a &#8220;disconnected recordset&#8221; (for the sorting stuff) get all users from active directory with an ADO query remove undesired results [...]]]></description>
			<content:encoded><![CDATA[<p>Austin Murtha sent me an email with a script question.<br />
His problem was a script that enumerates users and their OU&#8217;s.<br />
I have created the script below to help him.</p>
<p>What the script does:</p>
<ol>
<li>create a &#8220;disconnected recordset&#8221; (for the sorting stuff)</li>
<li>get all users from active directory with an ADO query</li>
<li>remove undesired results (if instr&#8230;)</li>
<li>add the rest to the disconnected recordset</li>
<li>sort the recordset</li>
<li>output to the screen</li>
</ol>
<p>Follow the next steps to run the script (no admin rights needed):</p>
<ul>
<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\usersinou.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:\temp&#8221;</li>
<li>give &#8220;cscript usersinou.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : usersinou.vbs
' Description : script to enumerate all Active Directory users sorted by OU
' Author : dirk adamsky - deludi bv
' Version : 1.0
' Date : 05-10-2011

Set DataList = CreateObject(&quot;ADOR.Recordset&quot;)
DataList.Fields.Append &quot;Name&quot;, 200, 255
DataList.Fields.Append &quot;OU&quot;, 200, 255
DataList.Open

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;)
strBase = &quot;&quot;
strFilter = &quot;(&amp;(objectCategory=person)(objectClass=user))&quot;
strAttributes = &quot;name,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
	If Instr(adoRecordset.Fields(&quot;distinguishedname&quot;).Value,&quot;OU=&quot;) &gt; 1 Then
		DataList.AddNew
		DataList(&quot;Name&quot;) = adoRecordset.Fields(&quot;name&quot;).Value
		DataList(&quot;OU&quot;) = Mid(adoRecordset.Fields(&quot;distinguishedname&quot;).Value, Instr(adoRecordset.Fields(&quot;distinguishedname&quot;).Value,&quot;OU=&quot;))
		Datalist.Update
	End If
	adoRecordset.MoveNext
Loop

adoRecordset.Close
adoConnection.Close

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

DataList.Sort = &quot;OU DESC&quot;
DataList.MoveFirst

Do Until DataList.EOF
     Wscript.Echo DataList.Fields.Item(&quot;OU&quot;) &amp; &quot; ; &quot; &amp; DataList.Fields.Item(&quot;Name&quot;)
     DataList.MoveNext
Loop

Datalist.Close
Set DataList = Nothing
</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%2Fou%2Factive-directory-vbscript-to-enumerate-all-active-directory-users-sorted-by-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/ou/active-directory-vbscript-to-enumerate-all-active-directory-users-sorted-by-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/ou/active-directory-vbscript-to-enumerate-all-active-directory-users-sorted-by-ou/"  data-text="Active Directory: Vbscript to enumerate all Active Directory users sorted by 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/ou/active-directory-vbscript-to-enumerate-all-active-directory-users-sorted-by-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/ou/active-directory-vbscript-to-enumerate-all-active-directory-users-sorted-by-ou/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Active Directory: VBScript to disable all user objects in an OU</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/active-directory-vbscript-to-disable-all-user-objects-in-an-ou/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/active-directory-vbscript-to-disable-all-user-objects-in-an-ou/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 13:08:09 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[active directory]]></category>
		<category><![CDATA[ou]]></category>
		<category><![CDATA[disabled]]></category>
		<category><![CDATA[resource mailbox]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=73</guid>
		<description><![CDATA[For some AD accounts (resource mailboxes) it is not necessary to login. It is a good idea to keep those accounts in a seperate OU. This script disables all user objects in a given OU. That way the resource mailbox will still function, only the AD account of this mailbox is no longer permitted to [...]]]></description>
			<content:encoded><![CDATA[<p>For some AD accounts (resource mailboxes) it is not necessary to login.<br />
It is a good idea to keep those accounts in a seperate OU.<br />
This script disables all user objects in a given OU.<br />
That way the resource mailbox will still function, only the AD account of this mailbox is no longer permitted to do logins.<br />
For optimal security the script can be run daily (windows scheduler).</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 OU path to your specific situation</li>
<li>save the script (for example c:tempdisableloginresourcemailboxes.vbs)</li>
<li>open a command prompt with administrative rights</li>
<li>go to &#8220;c:temp&#8221;</li>
<li>give &#8220;cscript disableloginresourcemailboxes.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : disableloginresourcemailboxes.vbs
' Description : script to disable all user objects in an OU
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 20-01-2010

Set objOU = GetObject(&quot;LDAP://OU=TestOU,DC=test,DC=org&quot;)
For Each objUser In objOU
	If objUser.class=&quot;user&quot; then
		objUser.AccountDisabled = True
		objUser.SetInfo
	End if
Next
Set objOU = Nothing
</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-disable-all-user-objects-in-an-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/active-directory-vbscript-to-disable-all-user-objects-in-an-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/active-directory-vbscript-to-disable-all-user-objects-in-an-ou/"  data-text="Active Directory: VBScript to disable all user objects in an 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/active-directory-vbscript-to-disable-all-user-objects-in-an-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/active-directory-vbscript-to-disable-all-user-objects-in-an-ou/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

