powershell LOGPARSER
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell LOGPARSER相关的知识,希望对你有一定的参考价值。
$CountryCode = 'HMB'
$LogPath = "D:\WA_Log\IIS\${CountryCode}"
function Get-LPRecord{
param($LPRecordSet)
$LPRecord = new-Object System.Management.Automation.PSObject
if( -not $LPRecordSet.atEnd())
{
$Record = $LPRecordSet.getRecord()
for($i = 0; $i -lt $LPRecordSet.getColumnCount();$i++)
{
$LPRecord | add-member NoteProperty $LPRecordSet.getColumnName($i) -value $Record.getValue($i)
}
}
return $LPRecord
}
function Exec-LogParser {
Param($Query)
$inputobj = New-Object -comObject MSUtil.LogQuery.IISIISInputFormat
$outputobj = New-Object -comObject MSUtil.LogQuery.IISOutputFormat
$LPQuery = new-object -com MSUtil.LogQuery
$LPRecordSet = $LPQuery.Execute($Query)
$LPRecords = new-object System.Management.Automation.PSObject[] 0
for(; -not $LPRecordSet.atEnd(); $LPRecordSet.moveNext())
{
# Add record
$LPRecord = Get-LPRecord($LPRecordSet)
$LPRecords += new-Object System.Management.Automation.PSObject
$RecordCount = $LPQueryResult.length-1
$LPRecords[$RecordCount] = $LPRecord
}
$LPRecordSet.Close();
$Results = $LPRecords
$Results
}
function GetCsUriStem {
$Query = "
Select Cs-Uri-Stem From ${LogPath}\u_ex180801.log
Where
Cs-Uri-Stem Not like '%.png'
And Cs-Uri-Stem Not like '%.pdf'
And Cs-Uri-Stem Not like '%.jpg'
And Cs-Uri-Stem Not like '%.txt'
And Cs-Uri-Stem Not like '%.json'
And Cs-Uri-Stem Not like '%.version'
And Cs-Uri-Stem Not like '%.ico'
Group By Cs-Uri-Stem
"
LogParser -rtp:-1 $Query -i:iisw3c
#$Results
}
$i = 0
$Uris = GetCsUristem
$UrisArr = ($Uris -Split "`r`n")
$FolderName = "D:\WA_Log\IIS\_Work\$((Get-Date).ToString('yyyyMMddhhmmss'))"
$New_Foler = New-Item -Path $FolderName -ItemType Directory
$Links = "<ul>"
$UrisArr[3..($UrisArr.Count - 8)] | % {
$ChartName = $_.Replace("/", "_").Replace(".", "_")
$Uri = $_
$Links += "<li>$Uri</li>`r`n"
$Query = "select TO_TIMESTAMP(date, time) as datetime, time-taken into ${FolderName}\${ChartName}.gif from ${LogPath}\u_ex180801.log where cs-uri-stem = '${Uri}' order by TO_TIMESTAMP(date, time)"
LogParser $Query -i:iisw3c -o:chart -chartType:Line -groupSize:1024x768 -chartTitle:$Uri
}
$Links = "</ul>"
$Links
以上是关于powershell LOGPARSER的主要内容,如果未能解决你的问题,请参考以下文章
C# 作业中的 LogParser
跪求高手帮忙!!!!解决logparser的问题
使用logparser.exe分析iis日志
Logparser介绍
用LogParser分析Windows日志
使用 LogParser 导入IIS Log到SqlServer数据库中