all scripts
This commit is contained in:
42
searchscript.ps1
Normal file
42
searchscript.ps1
Normal file
@@ -0,0 +1,42 @@
|
||||
$prod='rej-p'
|
||||
$servers = @( "$prod-app001", "$prod-bcm001", "$prod-bcm002", "$prod-app002", "$prod-app003", "$prod-app004", "$prod-web001", "$prod-web002", "$prod-web003", "$prod-web004", "$prod-web005", "$prod-web006", "$prod-web007", "$prod-web008")
|
||||
$pattern = Read-Host -Prompt "Enter the pattern to search for"
|
||||
$startDate = Read-Host -Prompt "Enter the start date (yyyy-MM-dd) [default: $(Get-Date -Format 'yyyy-MM-dd')]:"
|
||||
if (!$startDate) { $startDate = (Get-Date -Format "yyyy-MM-dd") }
|
||||
$endDate = Read-Host -Prompt "Enter the end date (yyyy-MM-dd) [default: $(Get-Date -Format 'yyyy-MM-dd')]:"
|
||||
if (!$endDate) { $endDate = (Get-Date -Format "yyyy-MM-dd") }
|
||||
$startTime = Read-Host -Prompt "Enter the start time (HH:mm:ss) [default: 08:00:00]:"
|
||||
if (!$startTime) { $startTime = "08:00:00" }
|
||||
$endTime = Read-Host -Prompt "Enter the end time (HH:mm:ss) [default: 16:00:00]:"
|
||||
if (!$endTime) { $endTime = "16:00:00" }
|
||||
$results = @()
|
||||
foreach ($server in $servers) {
|
||||
$path = "\\$server.rejprod.local\d-drive\IFSBOSystem\log\"
|
||||
Get-ChildItem -Path $path -Filter *.log | ForEach-Object {
|
||||
$logDate = $_.LastWriteTime.ToString("yyyy-MM-dd")
|
||||
$logTime = $_.LastWriteTime.ToString("HH:mm:ss")
|
||||
if (($logDate -ge $startDate) -and ($logDate -le $endDate) -and
|
||||
($logTime -ge $startTime) -and ($logTime -le $endTime)) {
|
||||
$matches = Select-String -Path $_.FullName -Pattern $pattern
|
||||
foreach ($match in $matches) {
|
||||
$results += [PSCustomObject]@{
|
||||
FileName = $_.Name
|
||||
Line = $match.Line
|
||||
Server = $server
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$results | Select-Object FileName, Line, Server | Export-Csv -Path "$PWD\result.csv" -NoTypeInformation
|
||||
|
||||
If ($results -ne $null)
|
||||
{
|
||||
start notepad++ .\result.csv
|
||||
}
|
||||
Else
|
||||
{
|
||||
Write-Host "!!NOTHING FOUND!!";
|
||||
}
|
||||
|
||||
#Write-Host $results
|
||||
Reference in New Issue
Block a user