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.