Posted On January 13, 2020

PowerShell: Change Process Priority Level

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Change Process Priority Level

Most programs would launch with normal priories and trigger child processes with varying priority levels, depending on the programmer’s intention. Well, you haz the tool to upgrade or downgrade running processes on-the-fly as desired – or for no reason (because you can). Here goes the snippets to render such statement as ‘oh yeah,’ (aka. ‘true’).

# Change-Process-Priority.ps1

$executable="WinMergeU.exe"
$priority="RealTime";

###### Powershell 4.0 or higher ######
$processPowerShell4=get-process -name $executable;
$processPowerShell4.PriorityClass=$priority;
write-host "$executable priority has been set to $($processPowerShell4.PriorityClass)";
# Change-Process-Priority.ps1

$executable="MsMpEng.exe"
$priority="Idle";

###### PowerShell 2.0 or higher ######
$command="Get-WMIObject Win32_process -filter 'name = `"$executable`"'"
$processPowerShell2=Invoke-Expression $command;

# Convert priority to integer
$value=switch ($priority.toLower()){
"idle" {64}
"belownormal" {16384}
"normal" {32}
"abovenormal" {32768}
"high" {128}
"realtime" {256}
}

$processPowerShell2.SetPriority($value)
write-host "$executable priority has been set to a priority mapping of $($processPowerShell2.Priority)";

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Gallery2 Random Highlight Mod

There's a SQL technical limitation where one may not update a table based on its…

WinRM Management Consideration

Infrastructure needs to be able to leverage scripting automation to perform Vulnerability Remediation, Resource Provisioning,…

Excel MD5 Hash Function

Go to the VB editor (Alt-F11), right-click on your workbook in theproject window, and click…