-
Notifications
You must be signed in to change notification settings - Fork 0
/
Check-EventLogSize.ps1
38 lines (35 loc) · 1.72 KB
/
Check-EventLogSize.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
$registrySettings = @(
@{Path = "HKLM:\SYSTEM\CurrentControlSet\Services\EventLog\Windows PowerShell"; Name = "MaxSize"; Value = 1073741824},
@{Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WINEVT\Channels\Microsoft-Powershell\Operational"; Name = "MaxSize"; Value = 1073741824},
@{Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WINEVT\Channels\Microsoft-Windows-TaskScheduler\Operational"; Name = "MaxSize"; Value = 274066954}
)
$remediationRequired = $false
$logFile = "C:\temp\log.txt"
foreach ($setting in $registrySettings) {
if (Test-Path $setting.Path) {
try {
$currentValue = Get-ItemPropertyValue -Path $setting.Path -Name $setting.Name -ErrorAction Stop
if ($currentValue -ne $setting.Value) {
Add-Content -Path $logFile -Value "Remediation required for $($setting.Path). Current value: $currentValue. Expected value: $($setting.Value)."
$remediationRequired = $true
} else {
Add-Content -Path $logFile -Value "No remediation required for $($setting.Path). Current value matches expected value: $($setting.Value)."
}
} catch {
Add-Content -Path $logFile -Value "MaxSize key does not exist at $($setting.Path). Remediation required."
$remediationRequired = $true
}
}
else {
Add-Content -Path $logFile -Value "Path $($setting.Path) does not exist. Remediation required."
$remediationRequired = $true
}
}
if ($remediationRequired) {
Add-Content -Path $logFile -Value "Remediation is required for one or more settings."
exit 1
}
else {
Add-Content -Path $logFile -Value "All settings are correct. No remediation required."
exit 0
}