-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogReader.ps1
More file actions
44 lines (42 loc) · 1.51 KB
/
LogReader.ps1
File metadata and controls
44 lines (42 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function Search-LogFiles{
param(
[Parameter(Position=1,ValueFromPipeline=$true)]
[String[]]$path=$_,
[String[]]$website=$null,
[ValidateSet("W3SVC")]
$logFormat="W3SVC"
)
foreach($site in $website){
if((Get-Website $site) -ne $null){
$siteInfo = Get-Website $site
$siteId = $siteInfo.Id
$logDir = ($siteInfo.LogFile.directory) + "\W3SVC" + $siteId
if($logDir.Contains("%SystemDrive%")){
$logDir = $logDir.Replace("%SystemDrive%", "$env:SystemDrive")
}
if(Test-Path $logDir){
$path = gci $logDir | select -exp FullName
}
}
}
foreach($logFile in $path){
if(Test-Path $logFile){
switch($logFormat){
W3SVC{
$headers = ([System.IO.File]::ReadLines($logFile) | select -Index 3).split(" ") | ?{$_ -ne "#Fields:"}
foreach($line in [System.IO.File]::ReadLines($logFile)){
if($line.StartsWith("#Fields:")){
$headers = $line.split(" ") | ?{$_ -ne "#Fields:"}
}
elseif(-not $line.StartsWith("#")){
ConvertFrom-Csv -Delimiter " " -Header $headers -InputObject $line
}
}
}
}
}
else{
Write-Host "No file found at $($logFile). Please check file location and try again."
}
}
}