Home > Microsoft Exchange Tips > Exchange Server Administration Tips > More in store for Private Store VBScript
Exchange Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

EXCHANGE SERVER ADMINISTRATION TIPS

More in store for Private Store VBScript


Will Schmied, Contributor
10.18.2004
Rating: -4.50- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Building on the simple script we had in the tip, "VBScript helps you keep an eye on the Private Store," here are two modifications of the same basic script that might suit your needs even more.

The useful aspect about all of these scripts is they are easy to change to suit your needs. So even though these came out of a need to keep an eye on the Exchange Private Store size, you could certainly do the same for any file--or perhaps even modify them to suit your specific needs.

The script in Listing 1 performs the same size checking you saw previously, but now instead of opening a dialog box with the size of the Private Store being displayed, it sends an e-mail (the content of which varies depending on the size of the file) using SMTP.

The script in Listing 2 again performs the same size checking you've seen before, but now instead of generating an e-mail when the size of the database is below the threshold value (MAX_FILE_SIZE), it simply logs the size, day, date and time into a text file for trend analysis. An e-mail alert is now only triggered when the threshold value has been exceeded. If you want to trim this script down, you can remove the day name generation portion, found between the 'Set value for day of week and 'Manipulate the log file remarks. You'll also want to remove reference to the dName variable as well.

You will need to supply values for the following items within the script:

  • MAX_FILE_SIZE – The size, in bytes, of your PRIV.EDB hat you want to trigger an action at. The script contains a value of 15 GB currently.

  • strFileSpec –- The full path to your PRIV.EDB file.

  • objEmail.From, objEmail.To, objEmail.Subject, objEmail.Textbody –- These define the content of the e-mail that will be generated, change to suit your needs. The example below includes the size of the database in the message. Note that you can send to multiple recipients by separating the e-mail addresses with a semi-colon.

  • smtpserver –- Put in the name or IP address of your smart host or SMTP server

  • fLog.OpenTextFile("<FILE> ") –- Put in the path and name of the text file you want to log to. By default, the script uses c:\PRIV_EDB.txt. The file will be created if it does not exist.

For ease of identification, I've marked them in bold.

Listing 1

' CHK_PRIV1.vbs
' WSH script to check file size of Exchange Private Store
' Sends email notification when run

' Set the initial conditions
' Variables for PRIV.EDB manipulation
Dim objFSO, objFile, strFileSpec
' Variable for the email object
Dim objEmail
' Max file size in bytes
Const MAX_FILE_SIZE = 16106127360
' Specify the file to check
strFileSpec = " <FULL PATH TO YOUR PRIV.EDB FILE>"

' Get the file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strFileSpec)

' Check the size of PRIV.EDB and perform an action
If objFile.Size > MAX_FILE_SIZE Then
' Send alert email if PRIV.EDB is over 15 GB in size
' Define the action
Set objEmail = CreateObject("CDO.Message")
' Who, What, Where, When, Why, How
objEmail.From = "me@you.com"
objEmail.To = "you@you.com"
objEmail.Subject = "Private Store is large!!!"
objEmail.Textbody = "WARNING! The Private Store is now " & objFile.Size/1073741824 & " GB!!!"
' Define email server settings
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"<SERVER OR SMART HOST>"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
' Send the email
objEmail.Send
Else
' Send status email if PRIV.EDB is under 15 GB in size
' Define the action
Set objEmail = CreateObject("CDO.Message")
' Who, What, Where, When, Why, How
objEmail.From = "me@you.com"
objEmail.To = "you@you.com"
objEmail.Subject = "Private Store size update!!!"
objEmail.Textbody = "The Private Store is currently " &
objFile.Size/1073741824 & " GB in size."
' Define email server settings
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"<SERVER OR SMART HOST>"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
' Send the email
objEmail.Send
End If

' Stop the script in case it doesn't automatically WScript.Quit

Listing 2
' CHK_PRIV2.vbs
' WSH script to check file size of Exchange Private Store
' Send email notification only in an alert condition

' Set the initial conditions
' Variables for PRIV.EDB manipulation
Dim objFSO, objFile, strFileSpec
' Variable for the email object
Dim objEmail
' Variables and constants for log file manipulation
Dim fLog, dFile, dNow, tNow, dValue, dName, fSize, tfSize
Const ForReading = 1, ForWriting = 2, ForAppending = 8
' Define the max file size in bytes
Const MAX_FILE_SIZE = 16106127360
' Specify the file to check
strFileSpec = "<FULL PATH TO YOUR PRIV.EDB FILE>"

' Get the file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strFileSpec)

' Check the size of PRIV.EDB and perform an action
If objFile.Size > MAX_FILE_SIZE Then
' Send alert email if PRIV.EDB is over 15 GB in size
' Define the action
Set objEmail = CreateObject("CDO.Message")
' Who, What, Where, When, Why, How
objEmail.From = "me@you.com"
objEmail.To = "you@you.com"
objEmail.Subject = "Private Store is large!!!"
objEmail.Textbody = "WARNING! The Private Store is now " &
tfSize & " GB!!!"
' Define email server settings
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"<SERVER OR SMART HOST>"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
' Send the email
objEmail.Send
Else
' Write the size of PRIV.EDB to a log file
' Trim the size output to four decimal places
fSize = objFile.Size/1073741824
tfSize = FormatNumber(fSize,4)
' Define date, time, day of week values
dNow = Date
tNow = Time
dValue = Weekday(Now)
'Set value for day of week
If dValue = 1 Then
dName = "Sunday"
ElseIf dValue = 2 Then
dName = "Monday"
Elseif dValue = 3 Then
dName = "Tuesday"
Elseif dValue = 4 Then
dName = "Wednesday"
Elseif dValue = 5 Then
dName = "Thursday"
Elseif dValue = 6 Then
dName = "Friday"
Elseif dValue = 7 Then
dName = "Saturday"
Else
dName = "Value out of range!"
End If
' Manipulate the log file
Set fLog = CreateObject("Scripting.FileSystemObject")
Set dFile = fLog.OpenTextFile("c:\PRIV_EDB.txt", ForAppending, True)
dFile.WriteLine "The Exchange Private store size is " & tfSize &
" GB at " & tNow & " on " & dName & ", " & dNow & "."
End If

' Stop the script in case it doesn't automatically WScript.Quit

The true power of these scripts comes not when you run manually, but when you use the Scheduled Tasks Wizard or the schtasks command (in Windows Server 2003 and Windows XP) to configure them to run every 3 or 4 hours (for example). It's then a set it and forget monitoring solution -- you could very easily do the same for other tasks as well.

As you can see, the potential with scripting is almost limitless as long as you have a need and a desire to accomplish a task in a more efficient method. In the future I'll examine some more scripting solutions that I've found help to make small improvements in an administrator's daily routine -- after all, every small improvement is a worthwhile one!


Will Schmied, BSET, MCSE, MCSA, is a systems engineer for a Fortune 500 shipping and transportation company. As a freelance writer, Will has written for Microsoft, Pearson, Sybex, Syngress, TechTarget, CNET, msexchange.org and several other organizations. Will has also worked with Microsoft in the MCSE exam-development process. You can visit Will at his MCSE certification portal, www.mcseworld.com.

Rate this Tip
To rate tips, you must be a member of SearchExchange.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
Exchange Server Administration Tips
Why too much memory can hurt Exchange Server 2007 performance
Microsoft Exchange Server backup method pros and cons
Migrating .PST files to an Exchange Server information store
Virtualizing Exchange Server 2007 with Microsoft's Hyper-V
Configure SMTP connection limits in Exchange Server 2003 and SBS
Five Microsoft Exchange Server backup worst practices
How to export Global Address List data to Microsoft Office Access
Create a group policy to prevent .PST file storage in Exchange 2007
Synchronizing the Windows Mobile emulator with Exchange Server 2007
Considerations for virtualizing an Exchange Server environment

Microsoft Exchange Server Database Management
Why boot an Exchange server from a storage area network (SAN)?
DetachPipe: Outlook add-in tool saves and restores email attachments
How to calculate white space in an Exchange streaming (.STM) file
An affordable Exchange Server database backup software option for SMBs
Solve server problems with the Exchange Troubleshooting Assistant tool
iSCSI SAN storage for Microsoft Exchange -- 5 tips in 5 minutes
Is an Exchange 2003 offline defrag needed prior to moving databases?
How to move Exchange Server email folders to another disk on the same computer
Should you use NTFS compression on Exchange Server files?
Tame your Exchange Server transaction logs

Microsoft Exchange Server Information Store
Migrating .PST files to an Exchange Server information store
Microsoft Exchange information store service stops responding
Tools that support Boolean searches of Exchange mailbox data and .PSTs
An introduction to Microsoft Exchange System Attendant
Defragment Exchange information store database files
How to find your Exchange Server store size limit
How can I run multiple mail stores and SMTP domains on one Exchange server?
Exchange Server information store issues FAQs
NEO Pro
Exchange Server Standard Maintenance Checklist

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2004 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts