mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 03:20:12 -08:00
feat: add scripts for event log size monitoring and old file removal
This commit is contained in:
19
powershell/event-log-size.ps1
Normal file
19
powershell/event-log-size.ps1
Normal file
@@ -0,0 +1,19 @@
|
||||
$logs = Get-EventLog -list
|
||||
foreach ($log in $logs) {
|
||||
$logName = $log.LogDisplayName
|
||||
$logFilePath = Join-Path -Path $env:SystemRoot -ChildPath "System32\winevt\Logs\$($log.LogFileName).evtx"
|
||||
|
||||
if (Test-Path $logFilePath) {
|
||||
$fileSize = (Get-Item $logFilePath).Length / 1MB
|
||||
} else {
|
||||
$fileSize = 0
|
||||
}
|
||||
|
||||
# Skip if file size is less than 1 MB
|
||||
if ($fileSize -lt 1) { continue }
|
||||
|
||||
$maxSize = $log.MaximumKilobytes / 1024 # Convert KB to MB
|
||||
$percentage = if ($maxSize -ne 0) { ($fileSize / $maxSize) * 100 } else { 0 }
|
||||
|
||||
Write-Host ("Log Name: {0}`nFile Size: {1:N2} MB`nMaximum Size: {2:N2} MB`nPercentage Full: {3}%`n---" -f $logName, $fileSize, $maxSize, [math]::Round($percentage, 2))
|
||||
}
|
||||
8
powershell/remove-files.ps1
Normal file
8
powershell/remove-files.ps1
Normal file
@@ -0,0 +1,8 @@
|
||||
$limit = (Get-Date).AddDays(-60)
|
||||
$path = "\\peranda-nas\media\backups\docker-data"
|
||||
|
||||
# Delete files older than the $limit.
|
||||
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force
|
||||
|
||||
# Delete any empty directories left behind after deleting the old files.
|
||||
Get-ChildItem -Path $path -Recurse -Force | Where-Object { $_.PSIsContainer -and (Get-ChildItem -Path $_.FullName -Recurse -Force | Where-Object { !$_.PSIsContainer }) -eq $null } | Remove-Item -Force -Recurse
|
||||
Reference in New Issue
Block a user