DEV Community

redhcp
redhcp

Posted on

Delete Logs Powershell

Powershell script for delete records older than the number of days established.

$Path = "c:\inetpub\logs\LogFiles"
$Daysback = "-60"
$CurrentDate = Get-Date
$DatetoDelete = $CurrentDate.AddDays($Daysback)
Get-ChildItem $Path -Recurse -Force | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item

Enter fullscreen mode Exit fullscreen mode

Top comments (0)