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

Manually Create a SSL Certificate with LetsEncrypt

Step 1: Install certbot-auto mkdir /etc/letsencryptcd /etc/letsencrypt/wget chmod a+x certbot-auto Step 2: Create the Cert…

Script to Backup Exchange Server

REM exchange.txtD:\Exchange2010\mailbox\TempDatabaseD:\Exchange2010\mailbox\Mailbox-Database-20150403D:\Exchange2010\mailbox\Public Folder Database 1998117930 REM exchangebackup.batecho offnet use S: \\FILESERVER01\backups\EXCHANGE-2010REM -------------------------------------------------------REM PARSE THE DATE…

PowerShell: Setting or Resetting User Password

$username='dragoncoin' $newPassword='SomeComplexPasswordHere' function resetPassword($username,$password){ if($env:userdnsdomain){ try{ Unlock-ADAccount -Identity $username Set-ADAccountPassword -Identity $username -Reset -NewPassword (ConvertTo-SecureString…