-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNew-EventLogSourceSimple.ps1
More file actions
60 lines (47 loc) · 2.17 KB
/
Copy pathNew-EventLogSourceSimple.ps1
File metadata and controls
60 lines (47 loc) · 2.17 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<#
.SYNOPSIS
Legt die Eventlog-Quelle 'ProcessMonitorService' im Anwendungsprotokoll
an - schlanke Variante.
.DESCRIPTION
Prueft, ob die Quelle schon existiert, legt sie sonst an und schreibt
einen Testeintrag.
Die ausfuehrlichere Fassung mit Pruefungen und Rueckmeldungen ist
New-EventLogSource.ps1 im selben Ordner.
.NOTES
Erfordert administrative Rechte: das Anlegen einer Eventlog-Quelle
schreibt in die Registry unter HKLM.
#>
#Requires -RunAsAdministrator
# Einfaches PowerShell Script zum Erstellen der Event Log-Quelle
# Muss als Administrator ausgeführt werden!
$SourceName = "ProcessMonitorService"
$LogName = "Application"
Write-Host "ProcessMonitorService Event Log Setup" -ForegroundColor Cyan
Write-Host "=====================================" -ForegroundColor Cyan
try {
# Prüfen ob Event Source bereits existiert
if ([System.Diagnostics.EventLog]::SourceExists($SourceName)) {
Write-Host "Event Log-Quelle '$SourceName' existiert bereits." -ForegroundColor Yellow
} else {
Write-Host "Erstelle Event Log-Quelle '$SourceName'..." -ForegroundColor White
[System.Diagnostics.EventLog]::CreateEventSource($SourceName, $LogName)
Write-Host "Event Log-Quelle erfolgreich erstellt!" -ForegroundColor Green
# Kurz warten
Start-Sleep -Seconds 2
}
# Test-Eintrag erstellen
Write-Host "Erstelle Test-Eintrag..." -ForegroundColor White
$EventLog = New-Object System.Diagnostics.EventLog($LogName)
$EventLog.Source = $SourceName
$EventLog.WriteEntry("ProcessMonitorService Event Log-Quelle Setup erfolgreich - $(Get-Date)", "Information", 1000)
$EventLog.Dispose()
Write-Host "Test-Eintrag erstellt!" -ForegroundColor Green
Write-Host ""
Write-Host "Setup erfolgreich abgeschlossen!" -ForegroundColor Green
Write-Host "Öffnen Sie den Event Viewer (eventvwr.msc) um den Eintrag zu prüfen." -ForegroundColor White
} catch {
Write-Host "FEHLER: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Stellen Sie sicher, dass Sie Administrator-Rechte haben." -ForegroundColor Yellow
}
Write-Host ""
Read-Host "Drücken Sie Enter zum Beenden"