 




<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Automatic E-Mail Purging Script</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/automatic-e-mail-purging-script/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/automatic-e-mail-purging-script/</link>
	<description></description>
	<lastBuildDate>Tue, 21 May 2013 22:12:11 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: h techy</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/automatic-e-mail-purging-script/#comment-52194</link>
		<dc:creator>h techy</dc:creator>
		<pubDate>Fri, 07 Mar 2008 17:40:45 +0000</pubDate>
		<guid isPermaLink="false">#comment-52194</guid>
		<description><![CDATA[Thanks for the links...I wil check them out...and yes...I want to clean up old e-mail....in a sense...but this is an ongoing process...due to our e-mail retention policy....anything older than 14 days needs to be automatically purged from the exchange server....as of right now...the script I provided is doing this...and running through my batch file where I have added each mailbox individually....my qestion with this...is if there is a way to run a script on EVERY mailbox instead of populating my batch file with individual mailboxes!]]></description>
		<content:encoded><![CDATA[<p>Thanks for the links&#8230;I wil check them out&#8230;and yes&#8230;I want to clean up old e-mail&#8230;.in a sense&#8230;but this is an ongoing process&#8230;due to our e-mail retention policy&#8230;.anything older than 14 days needs to be automatically purged from the exchange server&#8230;.as of right now&#8230;the script I provided is doing this&#8230;and running through my batch file where I have added each mailbox individually&#8230;.my qestion with this&#8230;is if there is a way to run a script on EVERY mailbox instead of populating my batch file with individual mailboxes!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: justthefacts</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/automatic-e-mail-purging-script/#comment-52187</link>
		<dc:creator>justthefacts</dc:creator>
		<pubDate>Fri, 07 Mar 2008 15:28:41 +0000</pubDate>
		<guid isPermaLink="false">#comment-52187</guid>
		<description><![CDATA[From your last response it appears you want to clean up old mailbox data from all your mailboxes on a specific server.  Have you considered using the Exchange Mailbox Manager utility.  The 3 links below provide information on how to use the utility as well as exclude mailboxes from being cleaned.   in short, its a matter a creating an additional Recipient Policy and chose Mailbox Manger Settings when prompted. 

http://support.microsoft.com/kb/319188/EN-US/
http://support.microsoft.com/kb/288115/en-us
http://support.microsoft.com/kb/302804/en-us]]></description>
		<content:encoded><![CDATA[<p>From your last response it appears you want to clean up old mailbox data from all your mailboxes on a specific server.  Have you considered using the Exchange Mailbox Manager utility.  The 3 links below provide information on how to use the utility as well as exclude mailboxes from being cleaned.   in short, its a matter a creating an additional Recipient Policy and chose Mailbox Manger Settings when prompted. </p>
<p><a href="http://support.microsoft.com/kb/319188/EN-US/" rel="nofollow">http://support.microsoft.com/kb/319188/EN-US/</a><br />
<a href="http://support.microsoft.com/kb/288115/en-us" rel="nofollow">http://support.microsoft.com/kb/288115/en-us</a><br />
<a href="http://support.microsoft.com/kb/302804/en-us" rel="nofollow">http://support.microsoft.com/kb/302804/en-us</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: h techy</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/automatic-e-mail-purging-script/#comment-52159</link>
		<dc:creator>h techy</dc:creator>
		<pubDate>Thu, 06 Mar 2008 19:39:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-52159</guid>
		<description><![CDATA[Ideally what I want the script to do is execute my batch file that I have....so that it runs on on all my mailboxed residing on our exchange server....and eliminate anthing in there older than the most current 14 days!]]></description>
		<content:encoded><![CDATA[<p>Ideally what I want the script to do is execute my batch file that I have&#8230;.so that it runs on on all my mailboxed residing on our exchange server&#8230;.and eliminate anthing in there older than the most current 14 days!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: h techy</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/automatic-e-mail-purging-script/#comment-52158</link>
		<dc:creator>h techy</dc:creator>
		<pubDate>Thu, 06 Mar 2008 19:35:59 +0000</pubDate>
		<guid isPermaLink="false">#comment-52158</guid>
		<description><![CDATA[Okay....here is the code for the entire script we are using...

&lt;b&gt;Dim obArgs,cArgs,iSize,ndate,tmailbox


Set obArgs = WScript.Arguments
tmailbox = obArgs.Item(0)

Main

Sub Main()
   Dim sConnString,domainname

   rem On Error Resume Next
   domainname = &quot;bogusdomain.com&quot; &#039; Use the Primary SMTP Exchange Domain name
  &#039; Set up connection string to mailbox.
   sConnString = &quot;file://./backofficestorage/&quot; &amp; domainname
   sConnString = sConnString &amp; &quot;/mbx/&quot; &amp; obArgs.Item(0) &amp; &quot;&quot;


   iSize = 0

   RecurseFolder(sConnString)
End Sub

Public Sub RecurseFolder(sConnString)

   Dim oConn
   Dim oRecSet
   Dim sSQL

   &#039; Set up SQL SELECT statement.
   sSQL = &quot;SELECT &quot;&quot;http://schemas.microsoft.com/mapi/proptag/x0e080003&quot;&quot;, &quot;
   sSQL = sSQL &amp; &quot;&quot;&quot;DAV:href&quot;&quot;,&quot;&quot;DAV:hassubs&quot;&quot;,&quot;&quot;DAV:displayname&quot;&quot; &quot;
   sSQL = sSQL &amp; &quot;FROM SCOPE (&#039;SHALLOW TRAVERSAL OF &quot;&quot;&quot; &amp; sConnString
   sSQL = sSQL &amp; &quot;&quot;&quot;&#039;) WHERE &quot;&quot;DAV:isfolder&quot;&quot; = true&quot;


   &#039; Create Connection object.
   Set oConn = CreateObject(&quot;ADODB.Connection&quot;)
   if Err.Number &lt;&gt; 0 then
      WScript.Echo &quot;Error creating ADO Connection object: &quot; &amp; Err.Number &amp; &quot; &quot; &amp; Err.Description
   end if

   &#039; Create RecordSet object.
   Set oRecSet = CreateObject(&quot;ADODB.Recordset&quot;)
   if Err.Number &lt;&gt; 0 then
      WScript.Echo &quot;Error creating ADO RecordSet object: &quot; &amp; Err.Number &amp; &quot; &quot; &amp; Err.Description
      Set oConn = Nothing
      Exit Sub
   end if

   &#039; Set provider to EXOLEDB.
   oConn.Provider = &quot;Exoledb.DataSource&quot;

   &#039; Open connection to folder.
 wscript.echo sConnString
   oConn.Open sConnString
   if Err.Number &lt;&gt; 0 then
      WScript.Echo &quot;Error opening connection: &quot; &amp; Err.Number &amp; &quot; &quot; &amp; Err.Description
      Set oRecSet = Nothing
      Set oConn = Nothing
      Exit Sub
   end if

   &#039; Open Recordset of all subfolders in folder.
   oRecSet.CursorLocation = 3
   oRecSet.Open sSQL, oConn.ConnectionString
   if Err.Number &lt;&gt; 0 then
      WScript.Echo &quot;Error opening recordset: &quot; &amp; Err.Number &amp; &quot; &quot; &amp; Err.Description
      oRecSet.Close
      oConn.Close
      Set oRecSet = Nothing
      Set oConn = Nothing
      Exit Sub
   end if

   if oRecSet.RecordCount = 0 then
      oRecSet.Close
      oConn.Close
      Set oRecSet = Nothing
      Set oConn = Nothing
      Exit Sub
   end if

   &#039; Move to first record.
   oRecSet.MoveFirst
   if Err.Number &lt;&gt; 0 then
      WScript.Echo &quot;Error moving to first record: &quot; &amp; Err.Number &amp; &quot; &quot; &amp; Err.Description
      oRecSet.Close
      oConn.Close
      Set oRecSet = Nothing
      Set oConn = Nothing
      Exit Sub
   end if

   &#039; Loop through all of the records, and then add the size of the 
   &#039; subfolders to obtain the total size.
   While oRecSet.EOF &lt;&gt; True
      &#039; Increment size.
      iSize = iSize + oRecSet.Fields.Item(&quot;http://schemas.microsoft.com/mapi/proptag/x0e080003&quot;)
      workfolderfp = oRecSet.Fields(&quot;DAV:href&quot;).value
      wscript.echo workfolderfp
      archivemail(workfolderfp)      
      &#039; If the folder has subfolders, recursively call RecurseFolder to process them.

      If oRecSet.Fields.Item(&quot;DAV:hassubs&quot;) = True then
         RecurseFolder oRecSet.Fields.Item(&quot;DAV:href&quot;)
      End If
      &#039; Move to next record.
      oRecSet.MoveNext
      if Err.Number &lt;&gt; 0 then
         WScript.Echo &quot;Error moving to next record: &quot; &amp; Err.Number &amp; &quot; &quot; &amp; Err.Description
         Set oRecSet = Nothing
         Set oConn = Nothing
         Exit Sub
      end if
   wend

   &#039; Close Recordset and Connection.
   oRecSet.Close
   if Err.Number &lt;&gt; 0 then
      WScript.Echo &quot;Error closing recordset: &quot; &amp; Err.Number &amp; &quot; &quot; &amp; Err.Description
      Set oRecSet = Nothing
      Set oConn = Nothing
      Exit Sub
   end if

   oConn.Close
   if Err.Number &lt;&gt; 0 then
      WScript.Echo &quot;Error closing connection: &quot; &amp; Err.Number &amp; &quot; &quot; &amp; Err.Description
      Set oRecSet = Nothing
      Set oConn = Nothing
      Exit Sub
   end if

   &#039; Clean up memory.
   Set oRecSet = Nothing
   Set oConn = Nothing
   wscript.echo sConnString
End Sub


Sub archivemail(workfolderfp)  

mailboxurl = workfolderfp
set Rec = CreateObject(&quot;ADODB.Record&quot;)
set Rs = CreateObject(&quot;ADODB.Recordset&quot;)
Set Conn = CreateObject(&quot;ADODB.Connection&quot;)
Conn.Provider = &quot;ExOLEDB.DataSource&quot;
Rec.Open mailboxurl, ,3
SSql = &quot;SELECT &quot;&quot;DAV:href&quot;&quot;, &quot;&quot;DAV:contentclass&quot;&quot; FROM scope(&#039;shallow traversal of &quot;&quot;&quot; &amp; mailboxurl &amp; &quot;&quot;&quot;&#039;) &quot; 
SSql = SSql &amp; &quot; WHERE (&quot;&quot;urn:schemas:httpmail:datereceived&quot;&quot; &lt; CAST(&quot;&quot;&quot; &amp; isodateit(now()-14) &amp; &quot;&quot;&quot; as &#039;dateTime&#039;)) AND &quot;&quot;DAV:isfolder&quot;&quot; = false&quot;                 
SSql = SSql &amp; &quot; AND &quot;&quot;DAV:contentclass&quot;&quot; = &#039;urn:content-classes:message&#039;&quot;
Rs.CursorLocation = 2 &#039;adUseServer = 2, adUseClient = 3
rs.open SSql, rec.ActiveConnection, 3
while not rs.eof
	rs.delete 1
	rs.movenext
wend
rs.close

end sub


function isodateit(datetocon)
	strDateTime = year(datetocon) &amp; &quot;-&quot;
	if (Month(datetocon) &lt; 10) then strDateTime = strDateTime &amp; &quot;0&quot;
	strDateTime = strDateTime &amp; Month(datetocon) &amp; &quot;-&quot;
	if (Day(datetocon) &lt; 10) then strDateTime = strDateTime &amp; &quot;0&quot;
	strDateTime = strDateTime &amp; Day(datetocon) &amp; &quot;T&quot; &amp; formatdatetime(datetocon,4) &amp; &quot;:00Z&quot;
	isodateit = strDateTime
end function&lt;/b&gt;

And to clarify....the portion that I am going in and editing everytime at this point is the batch file..and that is where i would add the following

&lt;b&gt;wscript /b c:\arcfolder\arcmailbox.vbs (enter mailbox name)&lt;/b&gt;]]></description>
		<content:encoded><![CDATA[<p>Okay&#8230;.here is the code for the entire script we are using&#8230;</p>
<p><b>Dim obArgs,cArgs,iSize,ndate,tmailbox</p>
<p>Set obArgs = WScript.Arguments<br />
tmailbox = obArgs.Item(0)</p>
<p>Main</p>
<p>Sub Main()<br />
   Dim sConnString,domainname</p>
<p>   rem On Error Resume Next<br />
   domainname = &#8220;bogusdomain.com&#8221; &#8216; Use the Primary SMTP Exchange Domain name<br />
  &#8216; Set up connection string to mailbox.<br />
   sConnString = &#8220;file://./backofficestorage/&#8221; &amp; domainname<br />
   sConnString = sConnString &amp; &#8220;/mbx/&#8221; &amp; obArgs.Item(0) &amp; &#8220;&#8221;</p>
<p>   iSize = 0</p>
<p>   RecurseFolder(sConnString)<br />
End Sub</p>
<p>Public Sub RecurseFolder(sConnString)</p>
<p>   Dim oConn<br />
   Dim oRecSet<br />
   Dim sSQL</p>
<p>   &#8216; Set up SQL SELECT statement.<br />
   sSQL = &#8220;SELECT &#8220;&#8221;http://schemas.microsoft.com/mapi/proptag/x0e080003&#8243;&#8221;, &#8221;<br />
   sSQL = sSQL &amp; &#8220;&#8221;"DAV:href&#8221;",&#8221;"DAV:hassubs&#8221;",&#8221;"DAV:displayname&#8221;" &#8221;<br />
   sSQL = sSQL &amp; &#8220;FROM SCOPE (&#8216;SHALLOW TRAVERSAL OF &#8220;&#8221;" &amp; sConnString<br />
   sSQL = sSQL &amp; &#8220;&#8221;"&#8216;) WHERE &#8220;&#8221;DAV:isfolder&#8221;" = true&#8221;</p>
<p>   &#8216; Create Connection object.<br />
   Set oConn = CreateObject(&#8220;ADODB.Connection&#8221;)<br />
   if Err.Number &lt;&gt; 0 then<br />
      WScript.Echo &#8220;Error creating ADO Connection object: &#8221; &amp; Err.Number &amp; &#8221; &#8221; &amp; Err.Description<br />
   end if</p>
<p>   &#8216; Create RecordSet object.<br />
   Set oRecSet = CreateObject(&#8220;ADODB.Recordset&#8221;)<br />
   if Err.Number &lt;&gt; 0 then<br />
      WScript.Echo &#8220;Error creating ADO RecordSet object: &#8221; &amp; Err.Number &amp; &#8221; &#8221; &amp; Err.Description<br />
      Set oConn = Nothing<br />
      Exit Sub<br />
   end if</p>
<p>   &#8216; Set provider to EXOLEDB.<br />
   oConn.Provider = &#8220;Exoledb.DataSource&#8221;</p>
<p>   &#8216; Open connection to folder.<br />
 wscript.echo sConnString<br />
   oConn.Open sConnString<br />
   if Err.Number &lt;&gt; 0 then<br />
      WScript.Echo &#8220;Error opening connection: &#8221; &amp; Err.Number &amp; &#8221; &#8221; &amp; Err.Description<br />
      Set oRecSet = Nothing<br />
      Set oConn = Nothing<br />
      Exit Sub<br />
   end if</p>
<p>   &#8216; Open Recordset of all subfolders in folder.<br />
   oRecSet.CursorLocation = 3<br />
   oRecSet.Open sSQL, oConn.ConnectionString<br />
   if Err.Number &lt;&gt; 0 then<br />
      WScript.Echo &#8220;Error opening recordset: &#8221; &amp; Err.Number &amp; &#8221; &#8221; &amp; Err.Description<br />
      oRecSet.Close<br />
      oConn.Close<br />
      Set oRecSet = Nothing<br />
      Set oConn = Nothing<br />
      Exit Sub<br />
   end if</p>
<p>   if oRecSet.RecordCount = 0 then<br />
      oRecSet.Close<br />
      oConn.Close<br />
      Set oRecSet = Nothing<br />
      Set oConn = Nothing<br />
      Exit Sub<br />
   end if</p>
<p>   &#8216; Move to first record.<br />
   oRecSet.MoveFirst<br />
   if Err.Number &lt;&gt; 0 then<br />
      WScript.Echo &#8220;Error moving to first record: &#8221; &amp; Err.Number &amp; &#8221; &#8221; &amp; Err.Description<br />
      oRecSet.Close<br />
      oConn.Close<br />
      Set oRecSet = Nothing<br />
      Set oConn = Nothing<br />
      Exit Sub<br />
   end if</p>
<p>   &#8216; Loop through all of the records, and then add the size of the<br />
   &#8216; subfolders to obtain the total size.<br />
   While oRecSet.EOF &lt;&gt; True<br />
      &#8216; Increment size.<br />
      iSize = iSize + oRecSet.Fields.Item(&#8220;http://schemas.microsoft.com/mapi/proptag/x0e080003&#8243;)<br />
      workfolderfp = oRecSet.Fields(&#8220;DAV:href&#8221;).value<br />
      wscript.echo workfolderfp<br />
      archivemail(workfolderfp)<br />
      &#8216; If the folder has subfolders, recursively call RecurseFolder to process them.</p>
<p>      If oRecSet.Fields.Item(&#8220;DAV:hassubs&#8221;) = True then<br />
         RecurseFolder oRecSet.Fields.Item(&#8220;DAV:href&#8221;)<br />
      End If<br />
      &#8216; Move to next record.<br />
      oRecSet.MoveNext<br />
      if Err.Number &lt;&gt; 0 then<br />
         WScript.Echo &#8220;Error moving to next record: &#8221; &amp; Err.Number &amp; &#8221; &#8221; &amp; Err.Description<br />
         Set oRecSet = Nothing<br />
         Set oConn = Nothing<br />
         Exit Sub<br />
      end if<br />
   wend</p>
<p>   &#8216; Close Recordset and Connection.<br />
   oRecSet.Close<br />
   if Err.Number &lt;&gt; 0 then<br />
      WScript.Echo &#8220;Error closing recordset: &#8221; &amp; Err.Number &amp; &#8221; &#8221; &amp; Err.Description<br />
      Set oRecSet = Nothing<br />
      Set oConn = Nothing<br />
      Exit Sub<br />
   end if</p>
<p>   oConn.Close<br />
   if Err.Number &lt;&gt; 0 then<br />
      WScript.Echo &#8220;Error closing connection: &#8221; &amp; Err.Number &amp; &#8221; &#8221; &amp; Err.Description<br />
      Set oRecSet = Nothing<br />
      Set oConn = Nothing<br />
      Exit Sub<br />
   end if</p>
<p>   &#8216; Clean up memory.<br />
   Set oRecSet = Nothing<br />
   Set oConn = Nothing<br />
   wscript.echo sConnString<br />
End Sub</p>
<p>Sub archivemail(workfolderfp)  </p>
<p>mailboxurl = workfolderfp<br />
set Rec = CreateObject(&#8220;ADODB.Record&#8221;)<br />
set Rs = CreateObject(&#8220;ADODB.Recordset&#8221;)<br />
Set Conn = CreateObject(&#8220;ADODB.Connection&#8221;)<br />
Conn.Provider = &#8220;ExOLEDB.DataSource&#8221;<br />
Rec.Open mailboxurl, ,3<br />
SSql = &#8220;SELECT &#8220;&#8221;DAV:href&#8221;", &#8220;&#8221;DAV:contentclass&#8221;" FROM scope(&#8216;shallow traversal of &#8220;&#8221;" &amp; mailboxurl &amp; &#8220;&#8221;"&#8216;) &#8221;<br />
SSql = SSql &amp; &#8221; WHERE (&#8220;&#8221;urn:schemas:httpmail:datereceived&#8221;" &lt; CAST(&#8220;&#8221;" &amp; isodateit(now()-14) &amp; &#8220;&#8221;" as &#8216;dateTime&#8217;)) AND &#8220;&#8221;DAV:isfolder&#8221;" = false&#8221;<br />
SSql = SSql &amp; &#8221; AND &#8220;&#8221;DAV:contentclass&#8221;" = &#8216;urn:content-classes:message&#8217;&#8221;<br />
Rs.CursorLocation = 2 &#8216;adUseServer = 2, adUseClient = 3<br />
rs.open SSql, rec.ActiveConnection, 3<br />
while not rs.eof<br />
	rs.delete 1<br />
	rs.movenext<br />
wend<br />
rs.close</p>
<p>end sub</p>
<p>function isodateit(datetocon)<br />
	strDateTime = year(datetocon) &amp; &#8220;-&#8221;<br />
	if (Month(datetocon) &lt; 10) then strDateTime = strDateTime &amp; &#8220;0&#8243;<br />
	strDateTime = strDateTime &amp; Month(datetocon) &amp; &#8220;-&#8221;<br />
	if (Day(datetocon) &lt; 10) then strDateTime = strDateTime &amp; &#8220;0&#8243;<br />
	strDateTime = strDateTime &amp; Day(datetocon) &amp; &#8220;T&#8221; &amp; formatdatetime(datetocon,4) &amp; &#8220;:00Z&#8221;<br />
	isodateit = strDateTime<br />
end function</b></p>
<p>And to clarify&#8230;.the portion that I am going in and editing everytime at this point is the batch file..and that is where i would add the following</p>
<p><b>wscript /b c:\arcfolder\arcmailbox.vbs (enter mailbox name)</b></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jlees</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/automatic-e-mail-purging-script/#comment-52082</link>
		<dc:creator>jlees</dc:creator>
		<pubDate>Wed, 05 Mar 2008 01:01:13 +0000</pubDate>
		<guid isPermaLink="false">#comment-52082</guid>
		<description><![CDATA[Be sure and check out my blog here on ITKE for more Network administration and VBSCRIPT tips.
&lt;b&gt;&lt;a href=&quot;http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/&quot;&gt;The VBScript Network and Systems Administrator&#039;s Cafe&lt;/a&gt;&lt;/b&gt;]]></description>
		<content:encoded><![CDATA[<p>Be sure and check out my blog here on ITKE for more Network administration and VBSCRIPT tips.<br />
<b><a href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/">The VBScript Network and Systems Administrator&#8217;s Cafe</a></b></p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 3/10 queries in 0.041 seconds using memcached
Object Caching 323/329 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-21 22:22:33 -->