<?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; command prompt</title>
	<atom:link href="http://vbscriptblog.com/tag/command-prompt/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 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 to enumerate the home directories and their sizes of all users in Active Directory V2</title>
		<link>http://vbscriptblog.com/vbscript/active-directory/home-directories/vbscript-to-enumerate-the-home-directories-and-their-sizes-of-all-users-in-active-directory-v2/</link>
		<comments>http://vbscriptblog.com/vbscript/active-directory/home-directories/vbscript-to-enumerate-the-home-directories-and-their-sizes-of-all-users-in-active-directory-v2/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 14:03:59 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[home directories]]></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[homedirectory]]></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=1257</guid>
		<description><![CDATA[This is a better version of my previous script to enumerate the home directory sizes of all active directory users. The problem with the previous one was that some home directory sizes were not calculated because the Filesystem object had difficulties with long pathnames. I did a search for a WMI based solution but unfortunately [...]]]></description>
			<content:encoded><![CDATA[<p>This is a better version of my <a 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/">previous script to enumerate the home directory sizes of all active directory users</a>. The problem with the previous one was that some home directory sizes were not calculated because the Filesystem object had difficulties with <a href="http://msdn.microsoft.com/en-us/library/ms165768.aspx">long pathnames</a>.<br />
I did a search for a WMI based solution but unfortunately i could not find one.<br />
To shorten the UNC path i decided to create a drive mapping with the Wscript Network object.<br />
It&#8217;s a bit of a &#8220;funky solution&#8221; but it works.</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\homedirectorysizev2.vbs)<br />
* open a command prompt<br />
* go to &#8220;c:\temp&#8221;<br />
* give &#8220;cscript homedirectorysizev2.vbs&#8221; (without quotes) and enter</p>
<p>Notes:<br />
1. when you run the script as administrator a h: network drive is created and disconnected for each user. When you want another drive letter you can change h: in the function to another drive letter.<br />
2. when you cancel the script before it is finished please manually disconnect the &#8220;h:&#8221; drive mapping  </p>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : homedirectorysizev2.vbs
' Description : script to enumerate the home directories and their sizes of all users in Active Directory v2
' Author : dirk adamsky - deludi bv
' Version : 2.00
' Date : 14-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 objNetwork = CreateObject(&quot;WScript.Network&quot;)
	Set objFSO = CreateObject(&quot;scripting.filesystemobject&quot;)
	objNetwork.MapNetworkDrive &quot;h:&quot;, strPath
	Set objFld = objFSO.GetFolder(&quot;h:&quot;)
	Foldersize = Round(objFld.Size/1048576,2)
	objNetwork.RemoveNetworkDrive &quot;h:&quot;
	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%2Fvbscript-to-enumerate-the-home-directories-and-their-sizes-of-all-users-in-active-directory-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/home-directories/vbscript-to-enumerate-the-home-directories-and-their-sizes-of-all-users-in-active-directory-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/home-directories/vbscript-to-enumerate-the-home-directories-and-their-sizes-of-all-users-in-active-directory-v2/"  data-text="VBscript to enumerate the home directories and their sizes of all users in Active Directory 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/home-directories/vbscript-to-enumerate-the-home-directories-and-their-sizes-of-all-users-in-active-directory-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/home-directories/vbscript-to-enumerate-the-home-directories-and-their-sizes-of-all-users-in-active-directory-v2/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" 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/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">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/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" 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/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">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/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" 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>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" 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/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">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/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" 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/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">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/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>2</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" 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/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">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/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 find files with specific extensions and creation date on remote servers</title>
		<link>http://vbscriptblog.com/vbscript/wmi/files-wmi/vbscript-and-wmi-vbscript-to-find-files-with-specific-extensions-and-creation-date-on-remote-servers/</link>
		<comments>http://vbscriptblog.com/vbscript/wmi/files-wmi/vbscript-and-wmi-vbscript-to-find-files-with-specific-extensions-and-creation-date-on-remote-servers/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 14:27:40 +0000</pubDate>
		<dc:creator>dirk adamsky</dc:creator>
				<category><![CDATA[files]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[cscript]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://deludi.nl/blog/?p=993</guid>
		<description><![CDATA[I recently got the question to find all Symantec BESR snaphot files older than 2 weeks (the retention period) on the company servers. This so that we could clear up some space on the snapshot volumes. I decided to make a general purpose script of it. You can use it to find old logfiles, etc. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently got the question to find all <a href="http://www.symantec.com/business/backup-exec-system-recovery-server-edition">Symantec BESR</a> snaphot files older than 2 weeks (the retention period) on the company servers. This so that we could clear up some space on the snapshot volumes.<br />
I decided to make a general purpose script of it.<br />
You can use it to find old logfiles, etc.</p>
<p>What the script does:</p>
<ul>
<li>create an array with all server you want to check (replace srv001, etc with your server names)</li>
<li>create a variable with a date of 2 weeks ago (Date -14)(can easily be changed in 30, 60 days ago)</li>
<li>change the variable date to the UTC date of 14 days ago (because WMI works with UTC dates)</li>
<li>for each server in the array</li>
<li>make a wmi connection</li>
<li>query for files with specific extensions and a creation date older than 14 days ago</li>
<li>in this example i took .txt and .csv extensions, change them in whatever filetype you want</li>
</ul>
<p>The script is tested in an win2003 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 strings &#8216;srv001&#8242; and &#8216;srv002&#8242; with the name of your exchange server</li>
<li>replace the extensions &#8216;txt&#8217; and &#8216;csv with the extensions you need</li>
<li>save the script (for example c:tempfindoldfileswithspecificextensions.vbs)(or something shorter..)</li>
<li>open a command prompt</li>
<li>go to &#8220;c:temp&#8221;</li>
<li>give &#8220;cscript findoldfileswithspecificextensions.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 findoldfileswithspecificextensions.vbs &gt; findoldfileswithspecificextensions.txt&#8221; (again without the quotes)</p>
<p>The script:</p>
<pre class="brush: vb; title: ; notranslate">
' Name : findoldfileswithspecificextensions.vbs
' Description : VBscript to find files with specific extensions and creation date on remote servers
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 21-03-2011
' Level: intermediate

arrServers = Array(&quot;srv001&quot;,&quot;srv002&quot;)
strDate = Date - 14
Set objDateToUtcDate = CreateObject(&quot;WbemScripting.SWbemDateTime&quot;)
objDateToUtcDate.SetVarDate(strDate)

For Each Server in arrServers
	Set objWMIService = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\&quot; &amp; Server &amp; &quot;rootcimv2&quot;)
	Set colFiles = objWMIService.ExecQuery(&quot;Select * from CIM_DataFile where (Extension = 'txt' or Extension = 'csv') and CreationDate &lt; '&quot; &amp; objDateToUtcDate &amp; &quot;'&quot;)
	For Each objFile in colFiles
		Wscript.Echo objFile.Name
	Next
	Set colFiles = Nothing
	Set objWMIService = Nothing
Next
Set objDateToUtcDate = 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%2Fwmi%2Ffiles-wmi%2Fvbscript-and-wmi-vbscript-to-find-files-with-specific-extensions-and-creation-date-on-remote-servers%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/wmi/files-wmi/vbscript-and-wmi-vbscript-to-find-files-with-specific-extensions-and-creation-date-on-remote-servers/"></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/files-wmi/vbscript-and-wmi-vbscript-to-find-files-with-specific-extensions-and-creation-date-on-remote-servers/"  data-text="VBscript and WMI: VBscript to find files with specific extensions and creation date on remote servers" 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/wmi/files-wmi/vbscript-and-wmi-vbscript-to-find-files-with-specific-extensions-and-creation-date-on-remote-servers/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://vbscriptblog.com/vbscript/wmi/files-wmi/vbscript-and-wmi-vbscript-to-find-files-with-specific-extensions-and-creation-date-on-remote-servers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

