Server 2019 custom PowerShell script is getting queued (Code 325)

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.