Skip to content

Commit

Permalink
Create Delete-Files-by-Age.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
rswio authored Jan 26, 2025
1 parent 18f567b commit d3a34d0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Files/Delete-Files-by-Age.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$LogPath = "C:\Logs" # Replace with the path to your log files
$RetentionDays = 30 # Replace with the number of days to retain logs

Get-ChildItem -Path $LogPath -Recurse | Where-Object {
$_.LastWriteTime -lt (Get-Date).AddDays(-$RetentionDays)
} | Remove-Item -Force
Write-Output "Old files removed from $LogPath"

0 comments on commit d3a34d0

Please sign in to comment.