How can I delete files with PowerShell without confirmation?

前端 未结 7 1919
暗喜
暗喜 2021-01-11 11:56

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

7条回答
  •  不要未来只要你来
    2021-01-11 12:38

    This worked for me:

    Get-ChildItem -Path "FolderToDelete" -Directory -recurse | where {$_.LastWriteTime -le $(get-date).Affffdays(-7)} | Remove-Item -recurse -force

提交回复
热议问题