I am trying to get the below PowerShell script to work using Task Scheduler. The problem is that it wont delete any files.
When I run it manually it needs a confirma
Delete a files folder\subfolders on D:\FOLDER (my example below), any files that older than 30 days.
Get-ChildItem -Path "D:\FOLDER\" -Recurse |? {($_.LastWriteTime -lt (Get-Date).AddDays(-30))} | Remove-Item -Recurse -Force -confirm:$false -Verbose
The -Force -Confirm:$false guarantees that you don't have to press Y or A every time it deletes a file or folder. The -Verbose displays what is being deleted.