Last active
September 29, 2025 14:57
-
-
Save vielhuber/38b7fa6c77dc344401485cd338ea4128 to your computer and use it in GitHub Desktop.
change task priority in task scheduler #windows #powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-ScheduledTask -TaskPath '\' | ForEach-Object { | |
$xml = [xml](Export-ScheduledTask -TaskName $_.TaskName -TaskPath $_.TaskPath -ErrorAction SilentlyContinue) | |
$node = $xml.SelectSingleNode("/*[local-name()='Task']/*[local-name()='Settings']/*[local-name()='Priority']") | |
$p = 7 | |
if ($node -and $node.InnerText) { $p = [int]$node.InnerText } | |
[pscustomobject]@{ | |
Task = "$($_.TaskPath)$($_.TaskName)".TrimStart('\') | |
Priority = $p | |
} | |
} | Format-Table -Auto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$tasks = @("Task1", "Task2", "Task3") | |
$priority = 4 | |
$tasks | ForEach-Object { | |
$taskName = $_ | |
try { | |
$currentTask = Get-ScheduledTask -TaskName $taskName -ErrorAction Stop | |
$settings = $currentTask.Settings | |
$settings.Priority = $priority | |
Set-ScheduledTask -TaskName $taskName -TaskPath $currentTask.TaskPath -Settings $settings | |
Write-Host "[OK] $taskName - Set priority to $priority." -ForegroundColor Green | |
} catch { | |
Write-Host "[ERROR] $taskName - Not found." -ForegroundColor Red | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set-ScheduledTask ... -User "FOO\bar" -Password "..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment