Skip to content

Instantly share code, notes, and snippets.

@gitfvb
Last active April 4, 2025 11:07
Show Gist options
  • Save gitfvb/44c8554bda6dc90ca7203de3437d0fd1 to your computer and use it in GitHub Desktop.
Save gitfvb/44c8554bda6dc90ca7203de3437d0fd1 to your computer and use it in GitHub Desktop.
Handle windows process priorities

To change the priority of the current running powershell process, do it like

#-----------------------------------------------
# SET UP PRIORITY
#-----------------------------------------------

$processId = [System.Diagnostics.Process]::GetCurrentProcess().ID
$currentPriority = ( get-process -Id $processId ).PriorityClass
If ( $currentPriority -ne "High" ) {
    ( get-process -Id $processId ).PriorityClass = "High"
    Write-Host "Changed process priority from $( $currentPriority ) to High"
}

To change the process priority (7 by default) of a scheduled task, do it like

$ct = Get-ScheduledTask -TaskName "Apteco - Run Build"
$ct.settings.Priority = 1

Priorities are documented here: https://learn.microsoft.com/en-us/windows/win32/taskschd/tasksettings-priority#remarks

Task priority Priority Class Priority Level
0 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL
1 HIGH_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST
2 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
3 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
4 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
5 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
6 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
7 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
8 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
9 IDLE_PRIORITY_CLASS THREAD_PRIORITY_LOWEST
10 IDLE_PRIORITY_CLASS THREAD_PRIORITY_IDLE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment