<?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; number</title>
	<atom:link href="http://vbscriptblog.com/tag/number/feed/" rel="self" type="application/rss+xml" />
	<link>http://vbscriptblog.com</link>
	<description>Scripting for Windows Sysadmins</description>
	<lastBuildDate>Wed, 11 Apr 2012 07:23:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<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" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></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"></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 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" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></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"></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>Active Directory: VBscript to enumerate the home directories and their sizes of all users in Active Directory</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/home-directories/active-directory-vbscript-to-enumerate-the-home-directories-and-their-sizes-of-all-users-in-active-directory/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/home-directories/active-directory-vbscript-to-enumerate-the-home-directories-and-their-sizes-of-all-users-in-active-directory/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 13:47:04 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[home directories]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[filesystem object]]></category>
		<category><![CDATA[home directory]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[number]]></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://vbscriptblog.com/?p=1245</guid>
		<description><![CDATA[Update: This script has some issues (path not found) with users with very large home folders and or homefolders with long pathnames. This is due to limitations of the Filesystem Object. I will see if i can make a &#8220;better solution&#8221;. Dave asked me for a script to enumerate all AD users, their home directories [...]]]></description>
			<content:encoded><![CDATA[<p>Update: This script has some issues (path not found) with users with very large home folders and or homefolders with long pathnames. This is due to limitations of the Filesystem Object. I will see if i can make a &#8220;better solution&#8221;.</p>
<p>Dave asked me for a script to enumerate all AD users, their home directories and the size of them.<br />
I already had the script to do that for <a href="http://vbscriptblog.com/vbscript/active-directory/roamingprofile/active-directory-vbscript-to-enumerate-the-roaming-profile-size-of-all-users-in-active-directory/">roaming profiles</a>.<br />
This script is a modified version.</p>
<p>Follow the next steps to run the script (admin rights needed for access to the home directories):</p>
<p>* open your favorite text editor<br />
* copy and paste the script into the editor<br />
* save the script (for example c:\temp\homedirectorysize.vbs)<br />
* open a command prompt<br />
* go to &#8220;c:\temp&#8221;<br />
* give &#8220;cscript homedirectorysize.vbs&#8221; (without quotes) and enter</p>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : homedirectorysize.vbs
' Description : script to enumerate the home directories and their sizes of all users in Active Directory
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 12-07-2011
' Level : intermediate

arrAttributes = Array(&quot;homeDirectory&quot;,&quot;displayname&quot;,&quot;mail&quot;) 

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;&lt;LDAP://&quot; &amp; objRootDSE.Get(&quot;defaultNamingContext&quot;) &amp; &quot;&gt;&quot;
Set objRootDSE = Nothing

strFilter = &quot;(&amp;(objectCategory=person)(objectClass=user)(homeDirectory=*))&quot;
strAttributes = Join(arrAttributes,&quot;,&quot;)
Wscript.Echo Join(arrAttributes,&quot;;&quot;) &amp; &quot; ; home directory size in MB&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
	strTempOutput = &quot;&quot;
	For i = 0 To Ubound(arrAttributes)
		strTempOutput =  strTempOutput &amp; &quot; ; &quot; &amp; adoRecordset.Fields(arrAttributes(i)).Value
		strOutput = Mid(Ltrim(strTempOutput),3)
	Next
	Wscript.Echo strOutput &amp; &quot; ; &quot; &amp; Foldersize (adoRecordset.Fields(arrAttributes(0)).Value) &amp; &quot; MB&quot;
	adoRecordset.MoveNext
Loop
adoRecordset.Close
adoConnection.Close
Set adoRecordset = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing

Function Foldersize(strPath)
	On Error Resume Next
	Set objFSO = CreateObject(&quot;scripting.filesystemobject&quot;)
	Set objFld = objFSO.GetFolder(strPath)
	Foldersize = Round(objFld.Size/1048576,2)
	Set objFld = Nothing
	Set objFSO = Nothing
End Function
</pre>
<p>When you have problems/questions please post a reply. Also can alo give a &#8216;star&#8217; rating. </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%2Fhome-directories%2Factive-directory-vbscript-to-enumerate-the-home-directories-and-their-sizes-of-all-users-in-active-directory%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" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></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/home-directories/active-directory-vbscript-to-enumerate-the-home-directories-and-their-sizes-of-all-users-in-active-directory/"></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/home-directories/active-directory-vbscript-to-enumerate-the-home-directories-and-their-sizes-of-all-users-in-active-directory/"  data-text="Active Directory: VBscript to enumerate the home directories and their sizes of all users in Active Directory" data-count="horizontal" data-via="dirkadamsky"></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/home-directories/active-directory-vbscript-to-enumerate-the-home-directories-and-their-sizes-of-all-users-in-active-directory/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/home-directories/active-directory-vbscript-to-enumerate-the-home-directories-and-their-sizes-of-all-users-in-active-directory/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Active Directory: VBscript to enumerate the local profile size of all computers and users in Active Directory</title>
		<link>http://vbscriptblog.com/vbscript/localprofiles/active-directory-vbscript-to-enumerate-the-local-profile-size-of-all-computers-and-users-in-active-directory/</link>
		<comments>http://vbscriptblog.com/vbscript/localprofiles/active-directory-vbscript-to-enumerate-the-local-profile-size-of-all-computers-and-users-in-active-directory/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 13:43:49 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[localprofiles]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[filesystem object]]></category>
		<category><![CDATA[folder]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[ping]]></category>
		<category><![CDATA[status]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://vbscriptblog.com/?p=1220</guid>
		<description><![CDATA[This script is made for Mike. He asked for a script to enumerate all local profiles and their size of the computers in his network. Complicating factor is the use of both Windows XP and Windows 7 clients. As you probably know that they have different local profile paths: Windows XP &#8211; &#8220;c:\documents and settings&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>This script is made for <a href="http://vbscriptblog.com/vbscript/active-directory/roamingprofile/active-directory-vbscript-to-enumerate-the-roaming-profile-size-of-all-users-in-active-directory/">Mike</a>.<br />
He asked for a script to enumerate all local profiles and their size of the computers in his network.<br />
Complicating factor is the use of both Windows XP and Windows 7 clients.<br />
As you probably know that they have different local profile paths:</p>
<p>Windows XP &#8211; &#8220;c:\documents and settings&#8221;</p>
<p>Windows 7 &#8211; &#8220;c:\users&#8221;</p>
<p>The script has to do:</p>
<ul>
<li>get all Windows XP and Windows 7 clients from Active Directory</li>
<li>check if they are online</li>
<li>get the local profiles and their sizes from each machine</li>
<li>write the values to a central logfile</li>
</ul>
<p>Follow the next steps to run the script (local admin rights needed for access to the target pc&#8217;s):</p>
<p>* open your favorite text editor<br />
* copy and paste the script into the editor<br />
* change the logfile location in line 73 (now c:\temp)<br />
* save the script (for example c:\temp\localprofiles.vbs)<br />
* open a command prompt<br />
* go to &#8220;c:\temp&#8221;<br />
* give &#8220;cscript localprofiles.vbs&#8221; (without quotes) and enter</p>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : localprofiles.vbs
' Description : script to enumerate the local profile size of all computers and users in Active Directory
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 28-06-2011

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;&lt;LDAP://&quot; &amp; objRootDSE.Get(&quot;defaultNamingContext&quot;) &amp; &quot;&gt;&quot;
strFilter = &quot;(&amp;(objectCategory=computer)(|(operatingSystem=Windows XP Professional)(operatingSystem=Windows 7*)))&quot;
strAttributes = &quot;name, operatingSystem&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
	strHostname = adoRecordset.Fields(&quot;name&quot;).Value
	If CheckStatus(strHostname) = True Then
		If Instr(adoRecordset.Fields(&quot;operatingSystem&quot;).Value, &quot;XP&quot;) &gt; 0 Then
			strLocalProfilePath = &quot;\Documents and Settings\&quot;
		ElseIf Instr(adoRecordset.Fields(&quot;operatingSystem&quot;).Value, &quot;7&quot;) &gt; 0 Then
			strLocalProfilePath = &quot;\users\&quot;
		End If
		GetLocalProfileSize strHostname, &quot;\\&quot; &amp; strHostname &amp; &quot;\c$&quot; &amp; strLocalProfilePath
	End If
	adoRecordset.MoveNext
Loop

adoRecordset.Close
adoConnection.Close

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

Function CheckStatus(strAddress)
	Dim objPing, objRetStatus
	Set objPing = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}&quot;).ExecQuery _
      (&quot;select * from Win32_PingStatus where address = '&quot; &amp; strAddress &amp; &quot;'&quot;)
	For Each objRetStatus In objPing
        If IsNull(objRetStatus.StatusCode) Or objRetStatus.StatusCode &lt;&gt; 0 Then
			CheckStatus = False
        Else
			CheckStatus = True
        End If
    Next
	Set objPing = Nothing
End Function

Function GetLocalProfileSize(strTargetMachine, strFolder)
	Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
	Set objFolder = objFSO.GetFolder(strFolder)
	For Each SubFolder in objFolder.SubFolders
		Logprint strTargetMachine &amp; &quot; ; &quot; &amp; SubFolder.Name &amp; &quot; ; &quot; &amp; SubFolder.Path &amp; &quot; ; &quot; &amp; Round(SubFolder.Size/1048576,2) &amp; &quot; MB&quot;
	Next
	Set objFolder = Nothing
	Set objFSO = Nothing
End Function

Function LogPrint(Message)
Const ForAppending = 8
strDate = Replace(Date,&quot;/&quot;,&quot;-&quot;)
Set ObjFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objTextFile = ObjFSO.OpenTextFile(&quot;c:\temp\&quot; &amp; strDate &amp; &quot;-localprofiles.csv&quot;, ForAppending, True)
    objTextFile.WriteLine Message
    objTextFile.Close
Set objTextFile = Nothing
Set ObjFSO = Nothing
End Function
</pre>
<p>When you have problems/questions please post a reply. Also can also give a &#8216;star&#8217; rating.</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%2Flocalprofiles%2Factive-directory-vbscript-to-enumerate-the-local-profile-size-of-all-computers-and-users-in-active-directory%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" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></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/localprofiles/active-directory-vbscript-to-enumerate-the-local-profile-size-of-all-computers-and-users-in-active-directory/"></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/localprofiles/active-directory-vbscript-to-enumerate-the-local-profile-size-of-all-computers-and-users-in-active-directory/"  data-text="Active Directory: VBscript to enumerate the local profile size of all computers and users in Active Directory" data-count="horizontal" data-via="dirkadamsky"></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/localprofiles/active-directory-vbscript-to-enumerate-the-local-profile-size-of-all-computers-and-users-in-active-directory/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/localprofiles/active-directory-vbscript-to-enumerate-the-local-profile-size-of-all-computers-and-users-in-active-directory/feed/</wfw:commentRss>
		<slash:comments>10</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" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></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"></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>VBscript: vbscript to enumerate the printers of Active Directory users and write the results to a file</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/printers/vbscript-vbscript-to-enumerate-the-printers-of-active-directory-users-and-write-the-results-to-a-file/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/printers/vbscript-vbscript-to-enumerate-the-printers-of-active-directory-users-and-write-the-results-to-a-file/#comments</comments>
		<pubDate>Fri, 27 May 2011 14:11:57 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[printers]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=1097</guid>
		<description><![CDATA[Today&#8217;s script is made for Hassan. He asked me to do a script that enumerates the printers of each user. Although that sounds easy it is a little complicated. The printers of each user are saved in the user profile (in the ntuser.dat file to be precisely). The easiest way to get a list of [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s script is made for <a href="http://deludi.nl/blog/vbscript/active-directory/sendasrights/active-directory-vbscript-to-enumerate-the-send-as-rights-on-a-user-or-resource-account/">Hassan</a>.<br />
He asked me to do a script that enumerates the printers of each user. Although that sounds easy it is a little complicated.</p>
<p>The printers of each user are saved in the user profile<br />
(in the ntuser.dat file to be precisely).<br />
The easiest way to get a list of printers per user is to add a small script to the <a href="http://technet.microsoft.com/en-us/library/cc758918%28WS.10%29.aspx">logon script</a> (can also be done with a <a href="http://en.wikipedia.org/wiki/Group_Policy">group policy</a>).<br />
The script below is such a script.<br />
It is very compact and can be run under the users credentials.<br />
The script does a WMI query (the <a href="http://msdn.microsoft.com/en-us/library/aa394363%28v=vs.85%29.aspx">Win32_Printer Class</a>) for the printers and writes the output to a file.<br />
Unfortunately we cannot use the same file for all users because of potential &#8220;file locking&#8221; problems.<br />
This can be adressed by using a database but that is beyond the scope of this article.</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 UNC path (&#8220;\srvXXXlogfiles&#8221;) in the LogToFile function on line 19 to your UNC path<br />
* save the script (for example c:tempprinters.vbs)<br />
* open a command prompt<br />
* go to &#8220;c:\temp&#8221;<br />
* give &#8220;cscript printers.vbs&#8221; (without quotes) and enter</p>
<p>To run the script as a logon script you can copy the script to the netlogon share or another user accessible location.</p>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : printers.vbs
' Description : script to enumerate the printers of Active Directory users and write the results to a file
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 27-05-2011

Set objNetwork = CreateObject(&quot;Wscript.Network&quot;)
Set objWMIService = GetObject(&quot;winmgmts:\.rootcimv2&quot;)
Set colPrinters = objWMIService.ExecQuery(&quot;Select * From Win32_Printer&quot;)
For Each objPrinter in colPrinters
    LogToFile(objNetwork.UserDomain &amp; &quot;&quot; &amp; objNetwork.UserName &amp; &quot; ; &quot; &amp; objPrinter.Name)
Next
Set colPrinters = Nothing
Set objWMIService = Nothing
Set objNetwork = Nothing 

Function LogToFile(Message)
Set ObjFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objTextFile = ObjFSO.OpenTextFile(&quot;\srvXXXlogfiles&quot; &amp; objNetwork.UserName &amp; Date &amp; &quot;.txt&quot;,8,True)
objTextFile.WriteLine Message
objTextFile.Close
Set objTextFile = Nothing
Set ObjFSO = 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%2Fprinters%2Fvbscript-vbscript-to-enumerate-the-printers-of-active-directory-users-and-write-the-results-to-a-file%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" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></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/printers/vbscript-vbscript-to-enumerate-the-printers-of-active-directory-users-and-write-the-results-to-a-file/"></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/printers/vbscript-vbscript-to-enumerate-the-printers-of-active-directory-users-and-write-the-results-to-a-file/"  data-text="VBscript: vbscript to enumerate the printers of Active Directory users and write the results to a file" data-count="horizontal" data-via="dirkadamsky"></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/printers/vbscript-vbscript-to-enumerate-the-printers-of-active-directory-users-and-write-the-results-to-a-file/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/printers/vbscript-vbscript-to-enumerate-the-printers-of-active-directory-users-and-write-the-results-to-a-file/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Active Directory and WMI: VBscript to enumerate a sorted list of all mailboxes and their size in your AD domain</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/email/active-directory-and-wmi-vbscript-to-enumerate-a-sorted-list-of-all-mailboxes-and-their-size-in-your-ad-domain/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/email/active-directory-and-wmi-vbscript-to-enumerate-a-sorted-list-of-all-mailboxes-and-their-size-in-your-ad-domain/#comments</comments>
		<pubDate>Tue, 17 May 2011 12:35:48 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[email]]></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[exchange]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[mailbox]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[server]]></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=1040</guid>
		<description><![CDATA[Today&#8217;s script is made for Gavin. It is an extension of my previous script to enumerate all Exchange mailboxes and their size. Gavin asked for a sorted list based on mailbox size. My first attempt was to use the VB Arraylist object (.Net needed on the script machine). Here&#8217;s an Arraylist example by Rob van [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s script is made for <a href="http://deludi.nl/blog/vbscript/active-directory/exchange-active-directory-vbscript/active-directory-and-wmi-vbscript-to-enumerate-all-mailboxes-and-their-size-of-your-ad-domain/">Gavin</a>.<br />
It is an extension of my previous script to enumerate all Exchange mailboxes and their size.<br />
Gavin asked for a sorted list based on mailbox size.</p>
<p>My first attempt was to use the VB Arraylist object (.Net needed on the script machine).<br />
Here&#8217;s an <a href="http://www.robvanderwoude.com/vbstech_data_arraylist.php">Arraylist example</a> by Rob van der Woude.<br />
The problem with the Arraylist object is that it is not made for sorting multi dimensional arrays.<br />
I can do some tricks by concatenating all values to a superstring.<br />
The problem is that sorting an Arraylist with superstrings will be next to impossible.</p>
<p>Luckily I found a better solution by using a <a href="http://sogeeky.blogspot.com/2006/08/vbscript-using-disconnected-recordset.html">disconnected recordset<br />
</a> (= a recordset without database connection).<br />
One thing to check is to use the <a href="http://www.w3schools.com/ado/prop_field_type.asp#datatypeenum">right datatype</a> for each variable.<br />
I declared the &#8220;size&#8221; variable as a &#8220;double precision floating point&#8221;.<br />
The other 2 were delared as &#8220;null-terminated character strings&#8221;.<br />
With the disconnected recordset you can do a lot of funky stuff like sorting, filtering and so on.<br />
I will certainly use the disconnected recordset object in new scripts.</p>
<p>I have tested the script in a large environment (~ 8500 mailboxes).<br />
It worked flawless (okay I had to test and modify it for half an hour or so).</p>
<p>What the script does:</p>
<ul>
<li>get all exchange servers from your AD domain</li>
<li>make a wmi connection to each server and create a list of the mailboxes and their size</li>
<li>put all values in a disconnected recordset, sort and output to the screen</li>
</ul>
<p>The script is tested in a win2003/exchange2003 environment.</p>
<p>Follow the next steps to run the script  (admin rights needed):</p>
<ul>
<li>copy and paste the script in your favorite text editor</li>
<li>save the script (for example c:tempsortedlistofallmailboxes.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:temp&#8221;</li>
<li>give &#8220;cscript sortedlistofallmailboxes.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : sortedlistofallmailboxes.vbs
' Description : script to enumerate all mailboxes and their size in your AD domain
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 17-05-2011
' Level: intermediate

Set DataList = CreateObject(&quot;ADOR.Recordset&quot;)
DataList.Fields.Append &quot;Servername&quot;, 200, 255
DataList.Fields.Append &quot;DisplayName&quot;, 200, 255
DataList.Fields.Append &quot;Size&quot;, 5
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;&lt;LDAP://&quot; &amp; objRootDSE.Get(&quot;configurationnamingcontext&quot;) &amp; &quot;&gt;&quot;
strFilter = &quot;(objectCategory=msExchExchangeServer)&quot;
strAttributes = &quot;name&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;) = 3
adoCommand.Properties(&quot;Cache Results&quot;) = False

Set adoRecordset = adoCommand.Execute

Do Until adoRecordset.EOF
 Set objWMIExchange = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!//&quot;&amp;_
 adoRecordset.Fields(&quot;name&quot;).Value &amp; &quot;/root/MicrosoftExchangeV2&quot;)
 Set colExchangeMailboxes = objWMIExchange.InstancesOf(&quot;Exchange_Mailbox&quot;)
 For Each objExchangeMailbox in colExchangeMailboxes
 If Left(objExchangeMailbox.StorageGroupName, 5) &lt;&gt; &quot;Recov&quot; Then
 DataList.AddNew
 DataList(&quot;Servername&quot;) = adoRecordset.Fields(&quot;name&quot;).Value
 DataList(&quot;DisplayName&quot;) = objExchangeMailbox.MailboxDisplayName
 DataList(&quot;Size&quot;) = Round(objExchangeMailbox.Size/1024,0)
 Datalist.Update
 End If
 Next
 Set colExchange_Mailboxes = Nothing
 Set objWMIExchange = Nothing
 adoRecordset.MoveNext
Loop

adoRecordset.Close
adoConnection.Close

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

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

Do Until DataList.EOF
 Wscript.Echo DataList.Fields.Item(&quot;Size&quot;) &amp; &quot; MB ; &quot; &amp; DataList.Fields.Item(&quot;DisplayName&quot;) &amp; &quot; ; &quot; &amp;_
 DataList.Fields.Item(&quot;Servername&quot;)
 DataList.MoveNext
Loop

Datalist.Close
Set DataList = Nothing
</pre>
<p>When you have problems/questions please post a reply or give a &#8216;star&#8217; rating.</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%2Femail%2Factive-directory-and-wmi-vbscript-to-enumerate-a-sorted-list-of-all-mailboxes-and-their-size-in-your-ad-domain%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" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></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/email/active-directory-and-wmi-vbscript-to-enumerate-a-sorted-list-of-all-mailboxes-and-their-size-in-your-ad-domain/"></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/email/active-directory-and-wmi-vbscript-to-enumerate-a-sorted-list-of-all-mailboxes-and-their-size-in-your-ad-domain/"  data-text="Active Directory and WMI: VBscript to enumerate a sorted list of all mailboxes and their size in your AD domain" data-count="horizontal" data-via="dirkadamsky"></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/email/active-directory-and-wmi-vbscript-to-enumerate-a-sorted-list-of-all-mailboxes-and-their-size-in-your-ad-domain/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/email/active-directory-and-wmi-vbscript-to-enumerate-a-sorted-list-of-all-mailboxes-and-their-size-in-your-ad-domain/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>VBscript: Vbscript to enumerate all accounts with Password Never Expires enabled in Active Directory</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/accounts/vbscript-vbscript-to-enumerate-all-accounts-with-password-never-expires-enabled-in-active-directory/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/accounts/vbscript-vbscript-to-enumerate-all-accounts-with-password-never-expires-enabled-in-active-directory/#comments</comments>
		<pubDate>Wed, 11 May 2011 10:59:31 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[accounts]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=1032</guid>
		<description><![CDATA[Had some questions on accounts with the &#8220;Password Never Expires&#8221; setting enabled. This script enumerates all user accounts in Active Directory en checks if the &#8220;Password Never Expires&#8221; marker is set. The check is no simple 1 or 0 but a bitwise comparison of the userAccountControl Value with ADS_UF_DONT_EXPIRE_PASSWD (or &#038;H10000 in vbs hex code). [...]]]></description>
			<content:encoded><![CDATA[<p>Had some questions on accounts with the &#8220;Password Never Expires&#8221; setting enabled.</p>
<p>This script enumerates all user accounts in Active Directory en checks if the &#8220;Password Never Expires&#8221;<br />
 marker is set.<br />
The check is no simple 1 or 0 but a bitwise comparison of the userAccountControl Value with<br />
 ADS_UF_DONT_EXPIRE_PASSWD (or &#038;H10000 in vbs hex code).<br />
userAccountControl Value for accounts with &#8220;Password Never Expires&#8221; not enabled -<br />
 Decimal: 512 &lt;=&gt; Binary: 1000000000.<br />
ADS_UF_DONT_EXPIRE_PASSWD &#8211; Hexadecimal (vbs):  &amp;H10000 &lt;=&gt;<br />
 Decimal: 65536 &lt;=&gt; Binary: 10000000000000000.</p>
<p>In the example above the binary comparison gives a zero as result, all non-zero results implicate that the value is enabled.</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\PasswordNeverExpires.vbs)<br />
* open a command prompt<br />
* go to &#8220;c:\temp&#8221;<br />
* give &#8220;cscript PasswordNeverExpires.vbs&#8221; (without quotes) and enter</p>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : PasswordNeverExpires.vbs
' Description : script to enumerate all accounts with Password Never Expires enabled in Active Directory
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 11-05-2011
' Level: Intermediate

Const ADS_UF_DONT_EXPIRE_PASSWD = &amp;H10000
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;&lt;LDAP://&quot; &amp; objRootDSE.Get(&quot;defaultNamingContext&quot;) &amp; &quot;&gt;&quot;
strFilter = &quot;(&amp;(objectCategory=person)(objectClass=user))&quot;
strAttributes = &quot;cn,mail,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 objUser = GetObject(&quot;LDAP://&quot; &amp; adoRecordset.Fields(&quot;distinguishedName&quot;).Value)
	If (objUser.userAccountControl And ADS_UF_DONT_EXPIRE_PASSWD) &lt;&gt; 0 Then
		Wscript.echo adoRecordset.Fields(&quot;cn&quot;).Value &amp; &quot; ; &quot; &amp; adoRecordset.Fields(&quot;mail&quot;).Value
	End If
	Set objUser = 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 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%2Faccounts%2Fvbscript-vbscript-to-enumerate-all-accounts-with-password-never-expires-enabled-in-active-directory%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" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></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/accounts/vbscript-vbscript-to-enumerate-all-accounts-with-password-never-expires-enabled-in-active-directory/"></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/accounts/vbscript-vbscript-to-enumerate-all-accounts-with-password-never-expires-enabled-in-active-directory/"  data-text="VBscript: Vbscript to enumerate all accounts with Password Never Expires enabled in Active Directory" data-count="horizontal" data-via="dirkadamsky"></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/accounts/vbscript-vbscript-to-enumerate-all-accounts-with-password-never-expires-enabled-in-active-directory/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/accounts/vbscript-vbscript-to-enumerate-all-accounts-with-password-never-expires-enabled-in-active-directory/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>VBscript and WMI: VBscript to enumerate all mailboxes on a given Exchange server</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/exchange-active-directory-vbscript/vbscript-and-wmi-vbscript-to-enumerate-all-mailboxes-on-a-given-exchange-server/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/exchange-active-directory-vbscript/vbscript-and-wmi-vbscript-to-enumerate-all-mailboxes-on-a-given-exchange-server/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 13:07:47 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[exchange]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[adsi]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=911</guid>
		<description><![CDATA[This script is made for Jeff Doty. What the script does: make a wmi connection to a given exchange server and create a list of the mailboxes and their size The script is tested in an win2003/exchange2003 environment. Follow the next steps to run the script (admin rights needed): copy and paste the script in [...]]]></description>
			<content:encoded><![CDATA[<p>This script is made for <a href="http://deludi.nl/blog/vbscript/active-directory/exchange-active-directory-vbscript/active-directory-and-wmi-vbscript-to-enumerate-all-mailboxes-and-their-size-of-your-ad-domain/comment-page-1/#comment-328">Jeff Doty</a>.</p>
<p>What the script does:</p>
<ul>
<li>make a wmi connection to a given exchange server and create a list of the mailboxes and their size</li>
</ul>
<p>The script is tested in an win2003/exchange2003 environment.</p>
<p>Follow the next steps to run the script  (admin rights needed):</p>
<ul>
<li>copy and paste the script in your favorite text editor</li>
<li>replace the string &#8216;srv001&#8242; with the name of your exchange server</li>
<li>save the script (for example c:tempmailboxes.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:temp&#8221;</li>
<li>give &#8220;cscript mailboxes.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>When you want the output in a file please give this command:</p>
<p>&#8220;cscript mailboxes.vbs &gt; mailboxes.txt&#8221; (again without the quotes)</p>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : mailboxes.vbs
' Description : script to enumerate all mailboxes on a given Exchange server
' Author : dirk adamsky - deludi bv
' Version : 1.10 (changed/corrected based on input by Mike)
' Date : 23-03-2011
' Level: intermediate

strServer = &quot;srv001&quot;
Const MinimalSize = 2048 'size in MB
Set objWMIExchange = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!//&quot; &amp; strServer &amp; &quot;/root/MicrosoftExchangeV2&quot;)
Set colExchangeMailboxes = objWMIExchange.InstancesOf(&quot;Exchange_Mailbox&quot;)
For Each objExchangeMailbox in colExchangeMailboxes
    If (Left(objExchangeMailbox.StorageGroupName, 5) &lt;&gt; &quot;Recov&quot;) And (Round(objExchangeMailbox.Size/1024,0) &gt; MinimalSize) Then
		Wscript.Echo objExchangeMailbox.MailboxDisplayName &amp; &quot; ; &quot; &amp;_
			Round(objExchangeMailbox.Size/1024,0) &amp; &quot; MB&quot;
	End If
Next
Set colExchange_Mailboxes = Nothing
Set objWMIExchange = Nothing
</pre>
<p>When you have problems/questions please post a reply or give a &#8216;star&#8217; rating.</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%2Fexchange-active-directory-vbscript%2Fvbscript-and-wmi-vbscript-to-enumerate-all-mailboxes-on-a-given-exchange-server%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" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></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/exchange-active-directory-vbscript/vbscript-and-wmi-vbscript-to-enumerate-all-mailboxes-on-a-given-exchange-server/"></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/exchange-active-directory-vbscript/vbscript-and-wmi-vbscript-to-enumerate-all-mailboxes-on-a-given-exchange-server/"  data-text="VBscript and WMI: VBscript to enumerate all mailboxes on a given Exchange server" data-count="horizontal" data-via="dirkadamsky"></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/exchange-active-directory-vbscript/vbscript-and-wmi-vbscript-to-enumerate-all-mailboxes-on-a-given-exchange-server/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/active-directory/exchange-active-directory-vbscript/vbscript-and-wmi-vbscript-to-enumerate-all-mailboxes-on-a-given-exchange-server/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Active Directory and WMI: VBscript to enumerate the ntfs rights of a given UNC path and a given level of subfolders</title>
		<link>http://vbscriptblog.com/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path-and-a-given-level-of-subfolders/</link>
		<comments>http://vbscriptblog.com/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path-and-a-given-level-of-subfolders/#comments</comments>
		<pubDate>Fri, 22 Oct 2010 11:39:09 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[ntfsrights]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[folder]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[subfolders]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=779</guid>
		<description><![CDATA[Today I have extended the previous script: it now also enumerates the NTFS rights of subfolders below the share. As a bonus the level of subfolders can be set Follow the next steps to run the script (admin rights needed for the WMI connection): copy and paste the script in your favorite text editor save [...]]]></description>
			<content:encoded><![CDATA[<p>Today I have extended the <a href="http://deludi.nl/blog/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path/">previous script:</a><br />
it now also enumerates the NTFS rights of subfolders below the share.<br />
As a bonus the level of subfolders can be set</p>
<p>Follow the next steps to run the script (admin rights needed for the <a href="http://en.wikipedia.org/wiki/Windows_Management_Instrumentation" target="_blank">WMI</a> connection):</p>
<ul>
<li>copy and paste the script in your favorite text editor</li>
<li>save the script (for example c:\temp\uncacl2.vbs)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:\temp&#8221;</li>
<li>give &#8220;cscript uncacl2.vbs&#8221; (without quotes) and enter</li>
</ul>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : uncacl2.vbs
' Description : script to enumerate the ntfs rights of a given UNC path and a given level of subfolders
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 22-10-2010

strUNCPathName = InputBox(&quot;please supply the UNC path to the shared folder&quot;)
strSubfolderLevel = InputBox(&quot;please supply the subfolder depth (1,2,etc.)&quot;)
arrUNC = split(strUNCPathName,&quot;\&quot;)
If Ubound(arrUNC) &gt; 3 Then
strRightPartOfPath = Mid(strUNCPathName,(Instr(strUNCPathName,arrUNC(4)) -1))
End If
Set objWMI = GetObject(&quot;winmgmts:\\&quot; &amp; arrUNC(2) &amp; &quot;\root\CIMV2&quot;)
Set objFileShare = objWMI.Get(&quot;Win32_Share.Name=&quot;&quot;&quot; &amp; arrUNC(3) &amp; &quot;&quot;&quot;&quot;)
If Right(arrUNC(3),1) = &quot;$&quot; And Len(arrUNC(3)) = 2 Then
strPath = objFileShare.Path &amp; Mid(strRightPartOfPath,2)
Else
strPath = objFileShare.Path &amp; strRightPartOfPath
End If
ShowACL strPath
ViewSubFolders strPath, strSubfolderLevel
Set objFileShare = Nothing
Set objWMI = Nothing

Function ViewSubfolders(strFolder, strMaxlevel)
Set colSubfolders = objWMI.ExecQuery(&quot;Associators Of {Win32_Directory.Name='&quot; &amp; strFolder &amp; &quot;'} &quot; &amp;_
&quot;Where AssocClass = Win32_Subdirectory ResultRole = PartComponent&quot;)
If strMaxlevel &gt;= 1 Then
    For Each SubFolder in colSubfolders
        wscript.echo SubFolder.Name
        ShowACL SubFolder.Name
        ViewSubFolders SubFolder.Name, (strMaxlevel - 1)
    Next
End If
Set colSubfolders = Nothing
End Function

Function ShowACL(strDir)
Set objFolderSecuritySettings = objWMI.Get(&quot;Win32_LogicalFileSecuritySetting.Path='&quot; &amp; strDir &amp; &quot;'&quot;)
objFolderSecuritySettings.GetSecurityDescriptor objSD
For Each objAce in objSD.DACL
    Select Case objAce.AccessMask
        Case 1179817
            strRights = &quot;read-only&quot;
        Case 2032127
            strRights = &quot;full-control&quot;
        Case 1245631
            strRights = &quot;change&quot;
    End Select
Wscript.Echo strUNCPathName &amp; &quot; ; &quot; &amp; strDir &amp; &quot; ; &quot; &amp; objAce.Trustee.Domain &amp; &quot; ; &quot; &amp; objAce.Trustee.Name &amp; &quot; ; &quot; &amp; strRights
Next
Set objSD = Nothing
Set objFolderSecuritySettings = Nothing
End Function
</pre>
<p>When you have problems/questions please post a reply or give a &#8216;star&#8217; rating.</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%2Fwmi%2Fntfsrights%2Factive-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path-and-a-given-level-of-subfolders%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" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></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/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path-and-a-given-level-of-subfolders/"></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/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path-and-a-given-level-of-subfolders/"  data-text="Active Directory and WMI: VBscript to enumerate the ntfs rights of a given UNC path and a given level of subfolders" data-count="horizontal" data-via="dirkadamsky"></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/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path-and-a-given-level-of-subfolders/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/wmi/ntfsrights/active-directory-and-wmi-vbscript-to-enumerate-the-ntfs-rights-of-a-given-unc-path-and-a-given-level-of-subfolders/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

