I'm attempting to create a task via powershell to delete some files older then 6 hours, if I execute the script from powershell there are no issues, if I try to execute from task scheduler nothing happens..
Call the Powershell.exe in my schedulded task:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Set this Parameters :
-NoProfile -ExecutionPolicy Bypass -Command -NonInteractive -File "C:\Scripts\DeleteFilesDiff3H.PS1"
What could be the problem of the task scheduler not launching my script?
Tried to aply some solutions provide to similar issues without success
$Path = "E:\MyPath"
$now = Get-Date
Get-Childitem * |
Where-Object { $_.LastWriteTime -le $now.AddHours(-6) } |
Remove-Item -Recurse -Force
I got this messages:
Task Scheduler started "{38dcd44b-4210-473b-921e-3cc1442ff03b}" instance of the "\Delete Files 3H" task for user "my user".
Task Engine "S-1-5-21-159114655-2248028564-2417230598-213599:My User:Interactive:LUA[2]" received a message from Task Scheduler service requesting to launch task "\Delete Files 3H" .
Task Scheduler launched "{38dcd44b-4210-473b-921e-3cc1442ff03b}" instance of task "\Delete Files 3H" due to a time trigger condition.
Task Scheduler successfully completed task "\Delete Files 3H" , instance "{618e6f44-b523-4c56-ae0b-04d3552391cc}" , action "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" with return code 0.
-Commandor-File, which serve distinct, mutually exclusive purposes. In your case, try removing-Command.