RE: OWA usage analysis script

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Jesse (Jesse_at_discussions.microsoft.com)
Date: 03/02/05


Date: Wed, 2 Mar 2005 05:57:03 -0800

I'll just keep this script updated on PSC
<http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=59150&lngWId=1&txtForceRefresh=3220058544866964>

"Jesse" wrote:

> Just ignore that last post, this does it all.
>
> ' -------------------------------------------------------------------------
> ' I got some of the script from the person below. Modified by Jesse Goodier
> ' -------------------------------------------------------------------------
> ' From the book Inside Active Directory, ISBN 0-201-61621-1
> ' Copyright (C) 2002 by Addison-Wesley
> ' Script by Sakari Kouti (see http://www.kouti.com)
> ' You have a royalty-free right to use, modify, reproduce and distribute
> ' this script (and/or any modified version) in any way you find useful,
> ' provided that you agree that Addison-Wesley or Sakari Kouti has no
> ' warranty, obligations or liability for the script. If you modify
> ' the script, you must retain this copyright notice.
> ' -------------------------------------------------------------------------
> 'tip- this is very cpu intensive!
> Option Explicit
> Const dbLangGeneral = ";LANGID=0x0409;CP=1252;COUNTRY=0"
> Const dbVersion40 = 64
> Dim objFSO,DBCer,LogsLocation,ArchiveLocation,legacyExchangeDN, objConn,
> RS,RS2, DRS, txtDealer, objTextFile, objDSE, objConnection, objCommand,
> i,MyFolder,filefound,filedate,DBLocation
>
> DBLocation="\\Server\Share\ExchangeLog.mdb"
> LogsLocation="\\OWAServer\admin$\system32\LogFiles\W3SVC1"
> ArchiveLocation="\\OWAServer\admin$\system32\LogFiles\W3SVC1\Archive\"
> Set objConn = CreateObject("ADODB.Connection")
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> CreateDB 'checks to see if DB exists.
> objConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" &DBLocation
>
> 'get the log files and date.
> set MyFolder=objFSO.GetFolder(LogsLocation)
> for each filefound in MyFolder.files
> wscript.echo filefound.name
> filedate= mid(filefound.name,5,2) &"/" &mid(filefound.name,7,2) &"/20"
> &mid(filefound.name,3,2)
> wscript.echo filedate
> 'don't process today's file.
> if cdate(filedate)<> date() then processfile filefound.name
> next
> wscript.quit
>
> sub processfile(filename)
> dim uid2,DontInsert,uid3
> 'Clean up temp table
> objconn.Execute "delete from UsageTemp"
> cmdCompactDB
> Set objTextFile = objFSO.OpenTextFile (LogsLocation &"\" &filename, 1)
> Do Until objTextFile.AtEndOfStream
> txtDealer = objTextFile.readline
> if instr(txtDealer,"exchange/") then
> uid2=split(txtDealer," ")
> if ubound(uid2)<7 then 'check to make sure the line is formatted how we
> expect it.
> DontInsert=True
> else
> uid3=split(uid2(7),"/")
> end if
> if ubound(uid3)<2 or DontInsert=True then
> DontInsert=True
> else
> if instr(uid3(2),"..") or instr(uid3(2),"%") or instr(uid3(2),"'") then
> DontInsert=True
> end if
> 'wscript.echo uid3(2)
> if DontInsert=False then
> if len(uid3(2))>1 then objconn.Execute "insert into UsageTemp (UID,TS)
> values('" &uid3(2) &"',#" &filedate &"#)"
> end if
> DontInsert=False
> end if
> Loop
>
> objTextFile.close
> objFSO.MoveFile LogsLocation &"\" &filename,ArchiveLocation &filename
> 'Normalize data
> set rs=objconn.Execute("select distinct UID from UsageTemp where ts=#"
> &filedate &"#")
> do until rs.EOF
> set RS2=objconn.Execute("select count(UID) as CoUID from UsageTemp where
> UID='" &RS("UID") &"' and ts=#" &filedate &"#")
> objconn.Execute "Insert into OWAUsage (UID,Hits,TS) Values('" &RS("UID")
> &"'," &RS2("CoUID") &",#" &filedate &"#)"
> objconn.Execute "delete from UsageTemp where UID='" &RS("UID") &"' and
> ts=#" &filedate &"#"
> rs.MoveNext
> loop
> wscript.echo " " &filename &" complete."
> end sub
>
> Sub CreateDB()
> 'objFSO.DeleteFile(DBLocation)
> if objFSO.FileExists(DBLocation) then exit sub
> Set DBCer = CreateObject("DAO.DBEngine.36")
> DBCer.CreateDatabase DBLocation, dbLangGeneral, dbVersion40
> Set DBCer = Nothing
> objConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" &DBLocation
> objConn.Execute "create table UsageTemp (ID Counter Primary Key, UID Text,
> Hits Long, TS DateTime)"
> objConn.Execute "create table OWAUsage (ID Counter Primary Key, UID Text,
> Hits Long)"
> objConn.Execute "CREATE UNIQUE INDEX IDIndex ON OWAUsage ([ID] ASC)"
> objConn.Close
> wscript.echo "Database created."
> wscript.quit
> end sub
>
> Sub cmdCompactDB()
> on error resume next 'in case someone has the db open. If you get the
> invalid object message, you need to compact.
> Set DBCer = CreateObject("DAO.DBEngine.36")
> objConn.Close
> if objFSO.FileExists("compacteddb.mdb") then
> objFSO.DeleteFile("compacteddb.mdb")
> DBCer.CompactDatabase DBLocation, "compacteddb.mdb", dbLangGeneral
> Set DBCer = Nothing
> objFSO.DeleteFile (DBLocation)
> objFSO.MoveFile "compacteddb.mdb", DBLocation
> wscript.echo " compact complete."
> objConn.Open
> End Sub



Relevant Pages

  • Re: Loop for only 10 cycles
    ... I will not comment on other issues, but altered your script ... I'm concerned that it will get caught in a never ending loop ... > Drive, intDrive, intTry, intTryMax ... > Sub QDRIVE ...
    (microsoft.public.windows.server.scripting)
  • Re: Detecting is hyperthreading is enabled with WMI?
    ... It is too bad that WMI does not give this info. ... have to be done to the script. ... Public Sub DisplayProcessorInfo ... dim ProcessorSet, Processor ...
    (microsoft.public.windowsxp.wmi)
  • Cant make this page work
    ... I can't make this script work properly. ... The script at the bottom of the html page ... Does someone have a perl ... sub output_trace_headers { ...
    (comp.lang.javascript)
  • Re: Syntax Problem...
    ... >> I'm tring to write a script that verifies if the time of the last ... sub Check_Mod ... But it runs in an infinite loop that I would only like to run every 60 ... Do I have the sleep function in the correct place, ...
    (comp.lang.perl.misc)
  • Re: Maybe I should try a different approach
    ... entire time my script is running, then have it close when my script is done and maybe have some dots keep adding to the text message until the script is fully completed? ... ' The "Three Ugly Hack" Script, ... Sub oATO_vbTimerEvent' timer event handler... ... Public Property Let Left ...
    (microsoft.public.scripting.vbscript)