Tip

More in store for Private Store VBScript

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

    Requires Free Membership to View

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.

This was first published in October 2004

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

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.