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 |