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;
      }
}

Related Posts by Categories

0 comments:

Post a Comment