Created
May 9, 2024 16:35
-
-
Save AaronSadlerUK/a6cce9f7be5e7c4ca9be000ce291a656 to your computer and use it in GitHub Desktop.
PowerShell scheduled task to automatically delete Umbraco log files older than 90days
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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