Tuesday, June 28, 2016

PowerShell v3 Function Change ProcessPriority

,
Not sure why I didnt put this one out when I wrote it. I come up with way too many functions...
function Change-ProcessPriority
{
      <#
            .EXAMPLE 1
                  Change-ProcessPriority "High"
                 
            .NOTES
                  Author: Will Steele (wlsteele@gmail.com)
                  Last Modified Date: 06/14/2012
                 
            .PARAMETER Priority
                  A mandatory string indicating the process level to which you want to
                  update a processes priority level.
      #>
           
      param(
            [Parameter(
                  Mandatory = $true
            )]
            [ValidateSet("AboveNormal","BelowNormal","High","Idle","Low","Normal","RealTime")]
            $Priority
      )
     
      if((Get-Process -Id $PID).PriorityClass -eq $Priority)
      {
            Write-Output "The process priority for PID ($PID) is already set to $($Priority).";
      }
      else
      {
            Write-Output "Setting the process priority for PID ($PID) to $($Priority).";
            (Get-Process -Id $PID).PriorityClass = $Priority;
      }
}

0 comments to “PowerShell v3 Function Change ProcessPriority”

Post a Comment

 

Computer Info Copyright © 2016 -- Powered by Blogger