I need Powershell script to delete log files from log folder path older than 180 days, which can be performed using task scheduler.
I wrote this script, but it's not working.
$Path = "C:\Users\akshay.tanpure\Music\logs"
$Daysback = "-180"
$CurrentDate = Get-Date
$DatetoDelete = $CurrentDate.AddDays($Daysback)
Get-ChildItem $Path -Recurse -Include *.log | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item -Force