Mmm perhaps one needs to
to create real-time or monthly
reports within any Windows
process or perhaps within the
Windows automation tool,
PowerShell?

Well here using PowerShell
to automate Log Parser one
can create almost any kind
of report - this one is a html
based report.

# Inform the user.
" "
"Creating the data file."

# Get some data for the report.
@"
machine1 user1 09/03/2008 10:15:27.20 Login
machine2 user2 09/03/2008 10:28:44.87 Login
machine3 user3 09/03/2008 10:32:51.23 LogOut
"@ | out-file LogInfo.txt -encoding ascii

" "
"Creating the Log Parser template (tpl) file."

# Create a template (TPL) file for Log Parser.
# The lpheader and lpfooter sections can also
# be in seperate files too. TPL can be any file
# type - not just html files.
@"
<lpheader>
<html>
<head>
<title>The Report</title>
<style>
td { font-family: Arial };
th { font-family: Arial };
</style>
</head>
<body bgcolor="cornsilk">
<center>
<h3>THE COMPANY REPORT</h3>
<table bordercolor="black"
border="1"
cellpadding="2"
cellspacing="2">
<tr>
<th colspan=5 bgcolor="black">
<font color="white">
Company Name - Logging Information </font></th>
</tr>
<tr>
<th align=left bgcolor="#C0C0C0">Machine</th>
<th align=left bgcolor="#C0C0C0">User</th>
<th align=left bgcolor="#C0C0C0">Date</th>
<th align=left bgcolor="#C0C0C0">Time</th>
<th align=left bgcolor="#C0C0C0">Log Type</th>
</tr>
</lpheader>

<lpbody>
<tr bgcolor="%color%">
<td>%machine%</td>
<td>%user%</td>
<td>%date%</td>
<td>%time%</td>
<TD>%LogType%</TD>
</tr>
</lpbody>

<lpfooter>
</table>
<br>
<img src="logcounts.gif">
<hr color="red" size=3>
<h3>%extramsg%</h3>
</body>
</center>
</html>
</lpfooter>
"@ | out-file loginout.lptpl -encoding ascii

" "
"Creating a process variable."

# Set a process variable so Log Parser can use it.
# If no message use $msg = " "
$msg = "=== Do not forget DOUGHNUTS in Room 43 Friday at 10 A.M. ==="
[System.Environment]::SetEnvironmentVariable("extramsg","$msg")

" "
"Running Log Parser with a tpl html file for outout."

# Get the html (created by Log Parser's tpl file)
# file's data information.
LogParser.exe "SELECT
Field1 AS Machine,
Field2 AS User,
Field3 AS Date,
Field4 AS Time,
Field5 AS LogType,
CASE LogType
WHEN 'Login' THEN 'LIGHTGREEN'
ELSE 'PINK'
END AS Color
INTO LogInfo.html
FROM LogInfo.txt " -i tsv -nFields 5 `
-headerRow off -iSeparator spaces `
-stats off -o tpl -tpl "$pwd\loginout.lpTpl"

" "
"Clearing the created process variable."

# Clear the set process's variables.
[System.Environment]::SetEnvironmentVariable("ExtraMsg","")

" "
"Creating a Log Parser chart."



# Get the tpl created html file's chart.
LogParser.exe "SELECT Field5,
COUNT(*)
INTO LogCounts.gif
FROM logInfo.txt
GROUP BY Field5
ORDER BY COUNT(*) DESC " -i tsv `
-nFields 5 -headerRow off `
-iSeparator spaces -stats off -o chart `
-chartType: columnClustered -values on `
-chartTitle "Total LogIn / LogOut Counts"

" "
"See the report?"

# Show the html file.
invoke-item loginfo.html

" "
"Done!"
" "
Exit

Have some fun - Log Parser it!