I found a script that can delete files over X days old and changed it a bit so that I will scan different network folders to see if there are files that are older than X days. Now when I run the script with PowerShell ISE the script is working fine and doing what it should do. It is taking about one hour.
Now when I try to schedule the script with Windows Task Scheduler, the task starts and completes 10 seconds later, but the script didn't run. So were no files deleted?
Scheduled Task setting:
Run task with account that has logon as batch priviledges
Run whether user is logged on or not
Run with highest priviledges
- Daily run
Program/script: Run a program C:\windows\system32\windowspowershell\v1.0\powershell.exe
Argument: -File “C:\scripts\deletefiles.ps1"
What am I doing wrong? Or why is it not running the script?
The script can be found here.