Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set PowerShell 'Start-Job' with low priority?

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

like image 361
Barry Chum Avatar asked Oct 21 '12 07:10

Barry Chum


2 Answers

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

like image 123
Roman Kuzmin Avatar answered Oct 10 '22 06:10

Roman Kuzmin


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
like image 34
Rahul Tripathi Avatar answered Oct 10 '22 08:10

Rahul Tripathi