SearchNetworkLogs.ps1
Neu erstellt.
This commit is contained in:
parent
bd27e39a0d
commit
50213b841c
37
Active_Directory/SearchNetworkLogs.ps1
Normal file
37
Active_Directory/SearchNetworkLogs.ps1
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
function Search-NetworkLogs {
|
||||||
|
param (
|
||||||
|
[string]$SharePath = "\\xw1239\Logs",
|
||||||
|
[string]$SearchTerm
|
||||||
|
)
|
||||||
|
|
||||||
|
# Prüfen, ob das Netzlaufwerk erreichbar ist
|
||||||
|
if (-Not (Test-Path $SharePath)) {
|
||||||
|
Write-Warning "Pfad '$SharePath' ist nicht erreichbar."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# Alle TXT-Dateien rekursiv finden
|
||||||
|
$txtFiles = Get-ChildItem -Path $SharePath -Recurse -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
if ($txtFiles.Count -eq 0) {
|
||||||
|
Write-Output "Keine .txt-Dateien gefunden unter '$SharePath'."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($file in $txtFiles) {
|
||||||
|
try {
|
||||||
|
# Durchsuche die Datei nach dem Suchbegriff
|
||||||
|
$matches = Select-String -Path $file.FullName -Pattern $SearchTerm -SimpleMatch
|
||||||
|
|
||||||
|
if ($matches) {
|
||||||
|
Write-Host "🔎 Treffer in Datei: $($file.FullName)" -ForegroundColor Cyan
|
||||||
|
foreach ($match in $matches) {
|
||||||
|
Write-Host " Zeile $($match.LineNumber): $($match.Line)" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
Write-Host ""
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Warning "Fehler beim Lesen der Datei '$($file.FullName)': $_"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user