![]() |
|
|
| Become a Columnist Microsoft Exchange Site Microsoft Support SiteMSDN Exchange Site | ||
|
|
Mailbox Crawl script Download Script The following script has been written to crawl through every eml object in every folder within a given mailbox. This can be useful in reporting or cleaning of mail stores. For example if its combined with the script in my content filtering article you can use this to produce a report that will provide you with the amount of storage space being used to store specific attachment types. Or you could use it to monitor or remove any undesirable mailbox content. How it works This is just a straight script that is designed to be run from the command line or a batch file that passes the mailbox alias of the mailbox you want to crawl as the parameter for the execution of the script. The front end of the code does just this it allows the passage of the mailbox alias as a parameter of the script then attaches it to form the complete mailbox URL. Note you need to modify this part of the code to include your full mailbox domain name (if you not sure what it is have a look at the M: drive on your server) note this script is designed to be run on the mailbox server this is why the file://./ is used you could also use the http://./ is you wish to run it on a remote workstation. For I = 0 to objArgs.Count - 1 The next part of the code setups up and opens an ADO record set that contains all the folders in the information store. It does this using a select query with the deep transverse option. Deep transverse queries are very resource intensive queries on a server and should be used sparingly. This is because they are a recursive query that will scan though for every object in the mailbox that matches the search criteria. For this reason I haven’t used this type of query to get access to every object in the mailbox store; doing so can have a very detrimental affect on the server resources in regards to processor and memory when querying large mailboxes. set WshShell = CreateObject("WScript.Shell") Once this record set is open the next part of the code creates another record set that contains all the items in the folder in the current record in the first record set. This time the query does a shallow transversal meaning that it only selects the items in that folder and doesn’t go any deeper. If Rs.RecordCount <> 0
Then This part of the code is where you can put your own processing section as a very simple example I put some code that writes the name of the mail URL to a log file.
Rs1.Movefirst The rest of the code closes down and cleans up all the objects Running this script To execute this script you can use a batch file or just execute it from the command line with the mailbox alias as the parameter eg mcraw1.vbs mailboxalias Extending this script This code has a lot of scope for extension by extending the second select query with the required parameters you can then extend the logging or other processing you want to do within this code. As an example of this have a look at this article where I’ve combined this script with a content filter script to produce a simple content scanning script for an mailbox store. |