Add a transcript to the script to see if it is encountering an error.
Windows Task Scheduler shows, Task completed successfully, but nothing happened
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 -
- The task is being run using an Admin account of server.
- Checked box to Run with highest privilege.
- Check box for " Run weather th euser is logged on or not"
- When I run the script in powershell it works fine.
- Under "Program/Script:" I tried putting just "powershell.exe" instead of entire path to powershell.exe.
- Added'-File' parameter before path under Argument.
- There is no space in script File name
- 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 ?
Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Server | User experience | Other
7 answers
Sort by: Most helpful
-
-
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
- Please Add the Start-Transcript and Stop-Transcript commands to your script and see if it encounters an error.
- 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--
-
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.
-
Rich Matheisen 47,901 Reputation points
2022-07-21T21:32:13.133+00:00 This works:
-
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.