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

Disable and Enable Trace Logging for Dynamics CRM

# Set common variables $serverTracingRegistry='Registry::HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\MSCRM' # Enable CRM Tracing Add-PSSnapin Microsoft.Crm.PowerShell $setting = Get-CrmSetting TraceSettings…

PowerShell: Alternative to Test-NetConnection for Legacy Windows

This little snippet is useful as a helper function to quickly determine port connectivity between…

Recover Windows CD Key

Set WshShell = CreateObject("WScript.Shell")MsgBox ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"))Function ConvertToKey(Key)Const KeyOffset = 52i = 28Chars = "BCDFGHJKMPQRTVWXY2346789"DoCur =…