Someone asked me about a script that would display details about the log files for each storage group on all the Exchange servers in their domain. While initially puzzled as to why this might be useful after a little thought the idea does bare a little fruit. Note the idea behind this is to look at the file details eg filename, date and size not the content of the file or to in anyway open or lock the files (which would be a bad thing). The general gist of the script is to enumerate the log file directory for each storage group and then count how many log files there are currently for that SG. While your counting them you can also add there sizes together to give you a figure of how much space you log files are taking up and you can also look at what the age of the oldest log file is this can let you know if your backups are working correctly and log files are being purged at the end of the backup cycle. If you start to think a little more laterally on this if where to snapshot this information at intervals during the day it can also become another Performance and usage indicator. Eg if you where to snap the size and number of your log files every hour you get could start to get a picture of the volume of transactions your mail database was processing what times it was busiest etc. Because transactions are more then just receiving and sending new mail this can act as a point of difference from other indicators you might look at (Remember performance monitoring is more then just measuring 1 dimensional metrics). You could even go as far as putting thresholds etc that might jink you to possible problems.
This script is generally based around the database file size script I posted here. I’ve done two versions of the script they both use an ADSI query to retrieve all the storage group objects within a domain and then connect to the servers based on the information that is parsed from some Ad properties on the storage group. The first script uses VBS’s FileSystemObject to connect to the administrative shares on a server and then uses the folder and files collection to read the file attributes. To make sure it only counts files that belong to this particular storage group the msExchESEParamBaseName property is used. This property contains the name prefix used for each storage groups log files. The rest of the script just counts the number of files, adds the size of the files together (and your always going to get something that dividable by 5120 KB if not start panicking). The second version uses WMI to do much the same thing this is useful if you have removed the admin shares on your server. One note on the WMI version is that if you have Daylight saving offsets then the file times might be out by this offset.
If put a downloadable copy of the code here the FSO version looks like
lfcount = 0
lfsize = 0
lfoldatenum = ""
set conn = createobject("ADODB.Connection")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
strNameingContext = iAdRootDSE.Get("configurationNamingContext")
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
sgQuery = "<LDAP://" & strNameingContext & ">;(objectCategory=msExchStorageGroup);
Com.ActiveConnection = Conn
Com.CommandText = sgQuery
Set Rs = Com.Execute
Wscript.echo "Storeage Groups"
While Not Rs.EOF
slen = instr(rs.fields("distinguishedName"),"CN=InformationStore,") + 23
elen = instr(rs.fields("distinguishedName"),"CN=Servers,")-1
Set fso = CreateObject("Scripting.FileSystemObject")
logfileunc = "\\" & mid(rs.fields("distinguishedName"),slen,elen-slen) & "\" &
left(rs.fields("msExchESEParamLogFilePath").value,1) & "$" &
set lfolder = fso.getfolder(logfileunc)
set lfiles = lfolder.files
for each lfile in lfiles
if left(lfile.name,3) = rs.fields("msExchESEParamBaseName").value and
right(lfile.name,3) = "log" then
lfcount = lfcount + 1
lfsize = lfsize + lfile.size
if lfcount = 1 then lfolddatenum = lfile.DateLastModified
if lfolddatenum > lfile.DateLastModified then
lfolddatenum = lfile.DateLastModified
wscript.echo "ServerName : " & mid(rs.fields("distinguishedName"),slen,elen-slen)
wscript.echo "Storage Group Name : " & rs.fields("adminDisplayName")
wscript.echo "Log file Path : " & rs.fields("msExchESEParamLogFilePath").value
wscript.echo "Log file Prefix : " & rs.fields("msExchESEParamBaseName").value
wscript.echo "Number of Log files in Directory : " & lfcount
wscript.echo "Disk Space being used : " & formatnumber(lfsize/1048576,2,0,0,0) &
wscript.echo "Oldest Log file in this Directory : " & lfolddatenum
lfcount = 0
lfsize = 0
lfolddatenum = ""
set mdbobj = Nothing
set pdbobj = Nothing
Set Rs = Nothing
Set Com = Nothing
Set Conn = Nothing