Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to check the Exchange database size

Exchange Maintenance

Script to check the Exchange database size

by  MoobyCow  Posted    (Edited  )
Because I know it's happened to a lot of people and because my DB size is getting close to the 16GB limit, I wrote a script to check the size and send a status email to my account every night (Task Scheduler).

I thought someone else might be able to use it so I'm posting it here. Just copy the text below and save it as a .vbs (putting in your correct info in email and path)

The date routine should run on 2000 or 2003 (which is why it's a bit more complex than you would expect), and it only checks for .edb and .stm files (change paths and email addresses where needed):

Set objEmail = CreateObject("CDO.Message")

dtmThisDay = Day(Date)
dtmThisMonth = Month(Date)
dtmThisYear = Year(Date)
dtmThisHour = hour(time)

if dtmthismonth < 10 then
dtmthismonth = "0" & dtmthismonth
end if

if dtmthisday < 10 then
dtmthisday = "0" & dtmthisday
end if

dtmbigdate = dtmThisyear & dtmThisMonth & dtmThisday & "000000.000000-300"

dtmTomDay = Day(Date + 1)
dtmTomMonth = Month(Date + 1)
dtmTomYear = Year(Date + 1)
dtmTomHour = hour(time + 1)

if dtmTommonth < 10 then
dtmTommonth = "0" & dtmTommonth
end if

if dtmTomday < 10 then
dtmTomday = "0" & dtmTomday
end if

dtmtomdate = dtmTomyear & dtmTomMonth & dtmTomday & "000000.000000-300"

strBackupName = dtmThisYear & "-" & dtmThisMonth & "-" & dtmThisDay
txtbdy = "Exhange Data Store:" & vbCRLF



strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Path = '\\Program Files\\Exchsrvr\\Mdbdata\\' " & _
"AND Drive = 'f:'")



For Each objFile in colFiles

If objFile.Extension = "edb" or objfile.Extension = "stm" Then

gbsize = objfile.filesize/1073741824
txtbdy = txtbdy & "File name: " & objFile.FileName & "." & objFile.Extension & vbCRLF
txtbdy = txtbdy & "File size: " & gbsize & vbCRLF & vbCRLF
end if

Next

Set colEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where TimeWritten >= '" _
& dtmbigdate & "' and TimeWritten < '" & dtmtomdate & "' and EventCode = '1221' and Logfile = 'Application'")

For each objEvent in colEvents

txtbdy = txtbdy & objEvent.Message & vbCRLF

Next


objEmail.From = "email@domain.com"
objEmail.To = "email.@domain.com"
objEmail.Subject = "Exchange Store Size: " & strBackupName
objEmail.Textbody = txtbdy
objEmail.Send
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top