-
Notifications
You must be signed in to change notification settings - Fork 12
/
GetLogContent.ps1
73 lines (63 loc) · 1.78 KB
/
GetLogContent.ps1
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
[CmdletBinding(DefaultParameterSetName="Path")]
param (
[Parameter(Mandatory=$true,
Position=0,
ParameterSetName="Path",
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string[]]
$Path,
[Parameter()]
[ValidateRange(0, 2GB)]
[int]
$Last = 1000,
[Parameter()]
[int]
$Minutes = 10,
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]
$Newline = $([Environment]::Newline)
)
Process
{
if ($psCmdlet.ParameterSetName -eq "Path")
{
# In the non-literal case we may need to resolve a wildcarded path
$resolvedPaths = @()
foreach ($apath in $Path)
{
$resolvedPaths += @(Resolve-Path $apath | Foreach { $_.Path })
}
}
else
{
$resolvedPaths = $LiteralPath
}
$date = [DateTime]::Now.AddMinutes(-$Minutes)
foreach ($rpath in $resolvedPaths)
{
if ($Minutes -eq 0) {
$lines = (.\Tail-Content.ps1 $rpath -Last $Last -Newline $Newline)
$lines = $output.Split($Newline)
$lines | Write-Output
}
else {
$output = (.\Tail-Content.ps1 $rpath -Last $Last -Newline $Newline)
$lines = $output.Split($Newline)
$lines | % {
if (($_ -match "^(\d+\-\d+\-\d+\s+\d+:\d+:\d+)")) {
$datepart = $_.Substring(0, $_.indexOf(' ', 12));
$logdate = [DateTime]::Parse($datepart)
$diff = $logdate - $date
if ( $diff.TotalSeconds -gt 0) {
Write-Output $_
}
}
}
}
}
}
#C:\windows\system32\LogFiles\HTTPERR\*
#select-string -Pattern "\d-\d-\d\s-\d:\d:\d\s" |