10

I would like to lower the priority of the jobs that I start with Start-Job in PowerShell scripts. Is this possible?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Barry Chum
  • 829
  • 3
  • 14
  • 23

2 Answers2

8

I used this trick right in a job's code (it can be optional, controlled by a parameter):

[System.Threading.Thread]::CurrentThread.Priority = 'Lowest'

Available priority values: Lowest, BelowNormal, Normal, AboveNormal, Highest

Roman Kuzmin
  • 40,627
  • 11
  • 95
  • 117
7

If you have launched it then you can use this:

 $a = gps powershell
 $a.PriorityClass = "BelowNormal"

Or you can use this using the key:

 Get-WmiObject Win32_process -filter 'name = "notepad.exe"' | foreach-object { $_.SetPriority(32) }

The priority codes are as follows:

 256 REALTIME
 128 HIGH_PRIORITY
 32768 ABOVE_NORMAL
 32 NORMAL
 16384 BELOW_NORMAL
 64 IDLE
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331