Thursday, June 30, 2016

PowerShell v2 Set Process Priority on Slow Scheduled Tasks

While troubleshooting some slow processes on a server I had my server guy take a look. After some wild goose chasing he discovered that Windows Server 2008 R2 defaults to a priority level of Low by default for scheduled tasks. All the troubleshooting we had done never led us to look at this, but, it explained everything perfectly. Once he exported the task in question to XML he noticed this little nugget:
7
The enumeration for this is "Low". Having changed the value to 4 (or "Normal" per this reference) and reimported he found the script associated with the job now ran as expected. Wondering how we could handle this programatically we found this link:
[MSH] How to change a Processs Priority 
from the days of Monad. Taking his suggestion one step further I came up with this:
(Get-Process -id $pid).PriorityClass = "Normal"
Using the $pid to automatically refer to the instance of PowerShell running my script I can handle this in a single line rather than having to export/manipulate XML or task objects.
 

Related Post:

0 comments:

Post a Comment

 
Copyright 2009 Information Blog
Powered By Blogger