Created
June 6, 2023 10:59
-
-
Save winkler-winsen/e4708d94794ec2b68a17a269e90884ed to your computer and use it in GitHub Desktop.
Log rotation afet x days / delete files older than x days
This file contains hidden or 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
$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