-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorLogScanner.ps1
More file actions
46 lines (35 loc) · 1.54 KB
/
Copy pathErrorLogScanner.ps1
File metadata and controls
46 lines (35 loc) · 1.54 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
45
46
# ErrorLogScanner.ps1
# v2
# Will Green
# 12/14/2018
# Add/remove errors from the scan_script_error_list.txt file for what to scan for in the logs.
# Add/remove full paths to what log directories to scan. Adjust $servercount value to equal the number
# of full paths to be scanned. Full compiled output of report will be sent to a file named: Scan-Report-DATE-TIME.txt
# Set variables
$servercount = "4"
$errorlistfile = $PSScriptRoot + '\' + "scan_script_error_list.txt"
$scandir = Get-Content -Path $errorlistfile -First $servercount
$reportfile = "Scan-Report-$(Get-Date -format "yyyyMMMdd-hhhhmm").txt"
$errorreport = $PSScriptRoot + '\' + $reportfile
$errorlist = Get-Content -Path $errorlistfile | Select -Skip $servercount
# Create report file
New-Item -Path $PSScriptRoot -Name $reportfile
# Loop thru list of log location paths
foreach ($loc in $scandir)
{
$loglist = Get-ChildItem -Name "TextLog_*" -Path $loc
$loghost = $loc.SubString(2).Split('.')[0]
$logapp = $loc.SubString(2).Split('\')[8]
Add-Content $errorreport "***************************************"
Add-Content $errorreport "SERVER: $loghost | APP: $logapp"
Add-Content $errorreport "***************************************"
# Loop thru list of logs
foreach ($log in $loglist)
{
# Loop thru list of errors
foreach ($scanerror in $errorlist)
{
Select-String -Path "$loc\$log" -Pattern $scanerror | Select-Object Filename,Line | Add-Content $errorreport -PassThru
}
}
}