0

I'm a newbie to Windows Server so I'm not sure if I'm doing something wrong, or if the server is at fault here.

I come from a Linux background and I wanted to make something similar to a cronjob. In Windows Server, this seems to be performed by the Task Scheduler. I created a simple .ps1 script to be executed at time XX:YY and also to be executed when I login.

Get-Date | Out-File C:\tmp\debug\debug.txt -Append

After testing it, the history log says "Warning ..... 325 ... queued ... XXXXXX". I've Googled for a solution, but the only thing Google tells me is to let it run parallel in case an existing instance of the process is already running. I've tried all that but it still puts the script in a queue. This queue doesn't seem to be processed.

I would appreciate any help.

10
  • 1
    What is the command line (minus any sensitive information) that you're using to run your script? Is this warning coming from output of a program the script is running, or actually showing up in Task Scheduler? How long would you expect this task to take to run and complete?
    – Sam Erde
    May 25, 2021 at 17:11
  • Please update with code you're trying to execute, the complete configuration of the scheduled task, and if any other tasks are scheduled to be executed on login or at the same time.
    – Colyn1337
    May 25, 2021 at 21:15
  • @SturdyErde it's just appending Get-Date in a file. Executing this task manually works perfectly fine. Scheduling it doesn't do anything.
    – Alb
    May 27, 2021 at 9:34
  • @SturdyErde these are simple tasks. For debugging purposes I've had them all deactivated and ended (multiple times) with the exception of a reboot task. Even this task got queued.
    – Alb
    May 27, 2021 at 10:19
  • Is this task scheduled to run as the same account that you're doing your interactive testing with, or something different? (Permissions?)
    – Sam Erde
    May 27, 2021 at 13:33

2 Answers 2

2
+50

It sounds like you may already have a few instances of the task queued up, with no timeout configured, and no termination in the script to handle potential errors.

I would recommend starting with a clean slate in the Task Scheduler by ending any existing instances of the task. Right-click on it and chose "End". You may need to do this multiple times if many instances are queued up.

There are a few things that you can tweak in the scheduled task's properties to help keep it moving.

Open the task properties dialog and go to the Settings tab:

  • As you have found you can set a new instance of the task to run in parallel. That may or may not be what you want. Your options there are: "Do not start a new instance", "Run a new instance in parallel", "Queue a new instance", or "Stop the existing instance."
  • Based on how long you expect this task's action to normally take, you probably want to change the setting to "Stop the task if it runs longer than [x] [units of time]. This setting can also be changed within each trigger's settings (see the Triggers tab of the task properties.)

In the task properties dialog, go to the Conditions tab:

  • Unless absolutely required, disable all of the conditions on this tab.

In the task properties dialog, scroll through the History tab to see if there is any status logged other than the "queued" ones. They may provide some insight into what is happening.

All that said, this will just help you run more instances of the task, but it won't solve why the task is not finishing on its own. It can be very helpful in these situations to add step-by-step logging into your PowerShell script so you can gain insight into how far that script is getting before things hang up. My suspicion is that you'll find the script is not completing, which results in the scheduled task never completing, and the next instance of the task never starting. Logging can reveal where this happens, because sometimes running a script manually isn't an exactly perfect test for what happens when the task scheduler runs your script.

As your updated question notes, you're just sending one simple command, so logging may not be very helpful in the long term, but still may reveal what the actual error is. (Try experimenting with the built-in $error variable.) It may be a permissions error if you are running the script as a different account than what you are testing with.

Finally, try adding an "Exit 0" line to the end of your script to see if that helps the Task Scheduler know that the script has ended successfully.

7
  • Is there a way to actually see what is currently in the queue? I have ended processes multiple times but after each reboot or logon, all tasks are back in the queue.
    – Alb
    May 27, 2021 at 9:11
  • The new task instances are happening because you added "at logon" as a trigger for the task (in addition to "at time xx:yy"). Just remove that trigger from the task properties, and it won't restart after every logon.
    – Sam Erde
    May 27, 2021 at 13:30
  • Sorry for the misconception. I'm trying to debug why all tasks (most of which are triggered by logon) are queued and not executed. My own task is for debugging and gets queued as well, regardless of the type of trigger or if any other items are queued at all.
    – Alb
    May 31, 2021 at 7:03
  • Right, and did you check the parallel task settings to see if they were set to allow multiple, to queue, or to end the current running task? (Described in my answer above.)
    – Sam Erde
    May 31, 2021 at 11:06
  • yes I did. I thought that a parallel running task would skip a queue and be executed as soon as it is triggered.
    – Alb
    May 31, 2021 at 11:35
0

I wouldnt think a script like that would be queued (its so short would take a mili sec to run). Its more likely something else is at play here. Try to run it manually, it might be that your script is not allowed to run, not signed : https:/go.microsoft.com/fwlink/?LinkID=135170

Notice also which account has permission to execute, especially with schedular if you allow it should be for the accounts you allow.

4
  • When I execute it directly in the task scheduler, it gets executed immediately without being queued.
    – Alb
    Jun 1, 2021 at 9:04
  • You might check if you have another powershell script active at that moment, or wait for it to finish, the trouble is you often dont see the console so you dont see the error why something is hanging when executing that way.
    – Peter
    Jun 1, 2021 at 9:19
  • How would I check that? Are there any logs for that? Is there another collection of scripts that are running? Is there an observer of some type that has an overview of this? Can this also hold true if I just execute "shutdown.exe /r", since it's not an explicit script running?
    – Alb
    Jun 1, 2021 at 9:24
  • 1
    sysinternals has a nice suite of tools proces explorer can show what processes are active. for exmaple pslist, and psexplorer show running processes.
    – Peter
    Jun 1, 2021 at 9:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .