您现在的位置是:网站首页> 编程资料编程资料
Powershell改变脚本执行优先权的代码分享_PowerShell_
2023-05-26
376人已围观
简介 Powershell改变脚本执行优先权的代码分享_PowerShell_
支持所有PS版本。
你可能需要在后台执行Powershell,例如复制文件,但是你又不想它影响你的CPU执行其它任务。
有一种方法就是降低Powershell执行的优先权,下面函数将介绍这个技巧:
复制代码 代码如下:
function Set-Priority
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true)]
[System.Diagnostics.ProcessPriorityClass]
$Priority
)
$process = Get-Process -Id $pid
$process.PriorityClass = $Priority
}
下面执行降低优先权:
复制代码 代码如下:
Set-Priority -Priority BelowNormal
你可以随时改回执行的优先级到正常水平,甚至提高脚本的优先级 – 增大额外开销可能会影响你UI的性能。
相关内容
- Powershell实现导入安装证书功能脚本分享_PowerShell_
- Windows Powershell 定义函数_PowerShell_
- Windows Powershell Switch 循环_PowerShell_
- Windows Powershell For 循环_PowerShell_
- Powershell小技巧之使用WS-Man来调用PowerShell命令_PowerShell_
- 使用HTTP api简单的远程执行PowerShell脚本_PowerShell_
- Powershell小技巧之开启关闭远程连接_PowerShell_
- PowerShell实现在控制台中插入绿色的打勾符号_PowerShell_
- PowerShell中终止管道的方法_PowerShell_
- Powershell实现监测服务器连通状态_PowerShell_
