6

I've been checking this for a while now. We have a script that creates a scheduled task and it seems that as described in many places across the net, the task priority this process and its descendants receive is 7:BelowNormal

Now this causes many issues in our testing environment which I'd like to avoid

The question here is whether I could create a GPO to override Windows' default scheduled task priority so that all new scheduled tasks will receive priority X (X being 'Normal' in my case)

I know there's an option to set the scheduled task priority upon creation but I'd like to avoid this so every new task will have a correct default priority and not the below-normal one

Thanks in advance

Ohad Benita
  • 533
  • 2
  • 8
  • 26
  • 1
    This doesn't necessarily have anything to do with powershell but Powershell is script language of choice in Windows, therefore I added the PowerShell tag – Ohad Benita Nov 09 '17 at 10:17

4 Answers4

5

You can edit your existing task by adding the settings option

$currentTask = Get-ScheduledTask -TaskName $taskName 
$settings = New-ScheduledTaskSettingsSet
$settings.Priority = 4
Set-ScheduledTask -TaskName $taskName -Trigger $currentTask.Triggers -Action $currentTask.Actions -Settings $settings -User "user" -Password "pass"
Alex Portnoy
  • 426
  • 1
  • 5
  • 14
5

Another way of doing this, without using powershell:

  1. Export the task from the GUI: in the Task Scheduler, right-click the task and select "Export…" and save the exported task in a file

  2. Change the priority
    2.1 Open the file in a text editor (like Notepad). This is the XML that defines the task. Each action will have a section, which contains <Settings>, which contains a <Priority> element.
    2.2 Change the value. The default value, for “below normal”, is 7. You can use either 6, 5, or 4 for “normal” priority. You will not usually want to go above “normal”. 6 will probably work for you.
    2.3 Save the file (for example, "c:\mytask.xml")

  3. Import the task using command line/schtasks:
    schtasks /DELETE /tn "\TASKSCHEDULER-FOLDER-PATH\TASK-IMPORT-NAME" (you need to first remove the existing task, to create a new one from the command line using schtasks)
    schtasks /create /xml "c:\mytask.xml" /tn "\TASKSCHEDULER-FOLDER-PATH\TASK-IMPORT-NAME"

I had 220 machines to do that, so I did it this way. Since all machines had the same configuration, I could copy the same XML file to all machines and recreate the scheduled task based on the XML. See a little more details on the different priorities here. This answer was based on this article.

msb
  • 3,899
  • 3
  • 31
  • 38
  • 2
    You can also import it via the GUI as well, by clicking 'Import' on the right side of the Task Scheduler window – Taegost May 14 '20 at 12:12
2

Unfortunately you can't change the default priority. But you can use Set-ScheduledTask to modify a existing task.

$task = Get-ScheduledTask -TaskName '...' // Your task's name
$settings = $task.Settings
$settings.Priority = 4
// For possible values see https://learn.microsoft.com/en-us/windows/win32/taskschd/tasksettings-priority#remarks
Set-ScheduledTask -TaskName $taskName -Settings $settings

Different from Alex Portnoy's answer this preserves other settings like WakeToRun.

RcINS
  • 61
  • 4
0

mostly easy method to doing this would be like this. its a bit too read however i am just explaining how it works and what each part means so not to have people thinking they are running a bad code.

  1. Open the Task Scheduler: Press Win + X on your keyboard, and select "Task Scheduler" from the Power User menu.
  2. Locate the scheduled task you want to modify, and double-click on it to open its properties.
  3. In the task's properties window, go to the "Actions" tab.
  4. Select the action associated with the task and click "Edit."
  5. In the "Edit Action" window, you'll find the "Program/script" field. Instead of directly entering the path to the executable, you'll modify it to include the command-line tool "cmd.exe" along with the necessary parameters.

For example, let's assume your original command was: C:\data\app\taskname.exe

Replace it with the following: cmd.exe /c start /b /low /wait C:\data\app\taskname.exe

In the modified command:

cmd.exe: Starts the Command Prompt. /c: Carries out the command specified by following string and then terminates.

start: Launches a new command prompt window to execute the task.

/b: Starts an application without creating a new Command Prompt window.

/low: Starts the application with low priority. can be swapped out with high normal ect. never Realtime.

/wait: Causes the command prompt to wait until the task is completed before exiting

Please note that while this workaround doesn't require a separate batch script, it still relies on using the command-line tool cmd.exe to achieve the desired result.

Teffers
  • 1
  • 3
  • 3
    This answer looks like it was generated by an AI (like ChatGPT), not by an actual human being. You should be aware that [posting AI-generated output is officially **BANNED** on Stack Overflow](https://meta.stackoverflow.com/q/421831). If this answer was indeed generated by an AI, then I strongly suggest you delete it before you get yourself into even bigger trouble: **WE TAKE PLAGIARISM SERIOUSLY HERE.** Please read: [Why posting GPT and ChatGPT generated answers is not currently allowed](https://stackoverflow.com/help/gpt-policy). – tchrist Jul 10 '23 at 12:40