Windows Task Scheduler shows, Task completed successfully, but nothing happened

Dey, Avijit 6 Reputation points
2022-07-20T09:17:35.077+00:00

I'm running a simple one liner powershell script (refer below) which works fine. But when I try to execute it using Task Scheduler ( both manual/scheduled) on Windows 2k12 R2 server the task shows as completed successfully but actually nothing happens.

The Script : - "Remove-Item -Path "C:\TESTFOLDER" -Include *.txt -Recurse"

What things I already checked -

  1. The task is being run using an Admin account of server.
  2. Checked box to Run with highest privilege.
  3. Check box for " Run weather th euser is logged on or not"
  4. When I run the script in powershell it works fine.
  5. Under "Program/Script:" I tried putting just "powershell.exe" instead of entire path to powershell.exe.
  6. Added'-File' parameter before path under Argument.
  7. There is no space in script File name
  8. No Firewall / AV stuff is blocking anything

I searched a lot over internet but don't find any proper answer anywhere. It's becoming highly frustrating.

Can anyone suggest what might be wrong ?

223491-ps-task-setup.jpg223501-scheduledtask-eventlogs.jpg

Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Server | User experience | Other
{count} votes

7 answers

Sort by: Most helpful
  1. MotoX80 36,401 Reputation points
    2022-07-20T23:43:57.697+00:00

  2. Limitless Technology 39,931 Reputation points
    2022-07-21T07:38:44.027+00:00

    Hello

    Thank you for your question and reaching out. I can understand you are having issues related to Task scheduler

    1. Please Add the Start-Transcript and Stop-Transcript commands to your script and see if it encounters an error.
    2. To schedule the PowerShell script, specify the following parameters:

    Action: Start a program
    Program\script: powershell
    Add arguments (optional): -File [Specify the file path to the script here]

    ----------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--


  3. Rafael da Rocha 5,251 Reputation points
    2022-07-21T17:15:42.527+00:00

    From what is visible in the screenshot, it would seem that the task isn't created correctly.

    In Program/Script you can reference powershell.exe directly, no need for the full path. This is just a suggestion for ease of use.

    In arguments, you must add the -File parameter before the path to the script.


  4. Rich Matheisen 47,901 Reputation points
    2022-07-21T21:32:13.133+00:00

    This works:

    223287-general.jpg223267-actions.jpg

    0 comments No comments

  5. MotoX80 36,401 Reputation points
    2022-07-21T22:32:11.65+00:00

    If you have a space in the folder name, then you need to put quotes around the file name.

    223362-image.png


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.