PowerShell Scripts, Tips, Expert Advices, Forums, and Resources

image rotation

Welcome to PowerShell.com, the educational and community site for Windows PowerShell People. Get a quick overview.

Latest Forum Posts

10-30-2014 - correct
10-30-2014 - Searching the security Logs
10-29-2014 - Merge array combining by column.

Latest Scripts

10-28-2014 - Get-FileTail
10-26-2014 - Yet another way to get mime type
10-26-2014 - Different ways to find os version

As a Powershell.com member you will have access to:

  • Daily PowerShell tips written by Microsoft MVPs and other leading Windows PowerShell experts
  • Free Windows PowerShell advice and training provided by Microsoft MVPs and other leading Windows PowerShell experts
  • Access to leading Windows PowerShell blogs
  • A free ebook, Mastering PowerShell, written by Microsoft MVP Dr. Tobias Weltner
PowerTip of the Day

Changing PowerShell Priority

All PowerShell versions

Maybe you’d like a PowerShell script to work in the background, for example copy some files, but you do not want the script to block your CPU or interfere with other tasks.

One way to slow down PowerShell scripts is to assign them a lower priority. Here is a function that can do the trick:

function Set-Priority
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$true)]
        [System.Diagnostics.ProcessPriorityClass]
        $Priority
    )
    
    $process = Get-Process -Id $pid
    $process.PriorityClass = $Priority
} 

To lower the priority of a script, call it like this:

 
Set-Priority -Priority BelowNormal 
 

You can change priority back to Normal anytime later, or even increase the priority to assign more power to a script – at the expense of other tasks, though, which may make your UI less responsive.

Twitter This Tip! ReTweet this Tip!

Copyright 2012 PowerShell.com. All rights reserved.