Skip to content

Instantly share code, notes, and snippets.

@AaronSadlerUK
Created May 9, 2024 16:35
Show Gist options
  • Save AaronSadlerUK/a6cce9f7be5e7c4ca9be000ce291a656 to your computer and use it in GitHub Desktop.
Save AaronSadlerUK/a6cce9f7be5e7c4ca9be000ce291a656 to your computer and use it in GitHub Desktop.
PowerShell scheduled task to automatically delete Umbraco log files older than 90days
# Set the directory path where you want to search
$directory = "E:\\"
# Get files matching the specified pattern and older than 90 days
$files = Get-ChildItem -Path $directory -Filter "UmbracoTraceLog*" -Recurse | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-90) }
$count = $files.Count
Write-Host "Number of files found: $count"
if ($count -gt 0) {
# Delete each file
foreach ($file in $files) {
Remove-Item -Path $file.FullName -Force
}
Write-Host "Deleted $count files."
} else {
Write-Host "No files found to delete."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment