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

PowerShell: Search Windows Event Logs

# searchWindowsEventsLog.ps1 $computername=$env:computername $logType='Security' $eventId=4732 $daysBack=365 $limit=9999 $messageLike="*Remote Desktop Users*" function searchWindowsEvents{ param( $computername=$env:computername $logType='Security'…

PowerShell: Add Quorum to Clusters

# SetClusterQuorum.ps1$clustersAndQuorums=@();$clustersAndQuorums+=[PSCustomObject]@{ClusterName='CLUSTER1';Quorum='\\FILESHERVER007\CLUSTER1$'};$clustersAndQuorums+=[PSCustomObject]@{ClusterName='CLUSTER2';Quorum='\\FILESHERVER007\CLUSTER2$'};function getViableNode{ param($nodes) foreach ($node in $nodes){ $bingo=Test-NetConnection $node -InformationLevel Quiet; if($bingo){return $node} }}…

Search for Windows computers in a certain subnet using Active Directory

# Search for Windows computers in a certain subnet using Active Directory $subnetQuery='10.10' $filterString='2016' $computers=Get-ADComputer…