Skip to content

Instantly share code, notes, and snippets.

@winkler-winsen
Created June 6, 2023 10:59
Show Gist options
  • Save winkler-winsen/e4708d94794ec2b68a17a269e90884ed to your computer and use it in GitHub Desktop.
Save winkler-winsen/e4708d94794ec2b68a17a269e90884ed to your computer and use it in GitHub Desktop.
Log rotation afet x days / delete files older than x days
$LogPath = "E:\"
$LogMaxDays = -30
$CurrentDate = Get-Date
$DateToDelete = $CurrentDate.Date.AddDays($LogMaxDays)
Get-ChildItem -Path $LogPath -File -Filter '*.log' | Where-Object LastWriteTime -LT $DateToDelete | Remove-Item -Confirm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment