Reputation: 543
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
Upvotes: 6
Views: 14939
Reputation: 63
This is my idea that WORKING perfectly:
$MyTask = "YourTaskName" #Name of scheduled task
$Task = Get-ScheduledTask -TaskName $MyTask
$TaskSettings = $Task.Settings
$OldPriority = $TaskSettings.Priority
# 0: Real Time, 1: High, 2: Above Normal, 3: Normal, 4: Below Normal, 5: Low, 7: Background
$TaskSettings.Priority = 2
Set-ScheduledTask -TaskName $MyTask -TaskPath $Task.TaskPath -Settings $TaskSettings |
ft -AutoSize TaskPath, TaskName, @{Name='OldPriority'; Expression = {$OldPriority}}, `
@{Name='NewPriority'; Expression = {((Get-ScheduledTask -TaskName $MyTask).Settings).Priority}}
I have put my own task name WinSCP-Task
inside the FTP-Sync
folder into code and below you can see its result:
TaskPath TaskName OldPriority NewPriority
-------- -------- ----------- -----------
\FTP-Sync\ WinSCP-Task 7 2
Upvotes: 1
Reputation: 101
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
.
Upvotes: 5
Reputation: 4438
Another way of doing this, without using powershell:
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
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")
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.
Upvotes: 6
Reputation: 476
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"
Upvotes: 5