We have seen how to call logparser from both powershell and C#. Let's show how it can be called from 2 other scripting languages:
VBScript:
Set objLogParser = CreateObject("MSUtil.LogQuery")
Set objInputFormat = CreateObject("MSUtil.LogQuery.IISW3CInputFormat")
Set objOutputFormat = CreateObject("MSUtil.LogQuery.W3COutputFormat")
outputfile = "c:\temp.log"
strQuery = "select date, time, s-sitename, s-computername, s-ip, cs-method, cs-uri-stem, cs-uri-query, s-port, cs-username, c-ip, cs(User-Agent), cs(Cookie), cs(Referer), cs-host, sc-status, sc-substatus, sc-win32-status, time-taken FROM d:\logs\ex*.log"
objLogParser.ExecuteBatch strQuery, objInputFormat, objOutputFormat
'to iterate through a recordset modify to
'Set objRecordSet = objLogParser.Execute (strQuery, objInputFormat)
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.Run outputfile
JScript: (documented sample in .chm)
var oLogQuery = new ActiveXObject("MSUtil.LogQuery");I don't really use vbscript or jscript, but for those that use it you can find the samples above and play with them to make it work for you.
// Make sure that parse error messages are collected
oLogQuery.maxParseErrors = 100;
// Create query text
var strQuery = "SELECT sc-bytes INTO C:\\output.csv FROM ex040528.log";
// Execute query
oLogQuery.ExecuteBatch(strQuery);
// Check if errors occurred
if( oLogQuery.lastError != 0 )
{
WScript.Echo("Errors occurred!");
var oMessages = new Enumerator( oLogQuery.errorMessages );
for(; !oMessages.atEnd(); oMessages.moveNext())
{
WScript.Echo("Error message: " + oMessages.item());
}
}
else
{
WScript.Echo("Executed successfully!");
}
No comments:
Post a Comment