我想终止所有运行时间超过5分钟的Internet Explorer进程。这必须是使用Powershell v1.0的一行命令。
另一种方式:
get-process iexplore | ? { ([DateTime]::Now - $_.StartTime).TotalSeconds -gt 300 } | stop-process
Get-Process iexplore -ErrorAction SilentlyContinue |
Where-Object { $_.StartTime -and (Get-Date).AddMinutes(-5) -gt $_.StartTime } |
Stop-Process
至少在powershell v2上,以下命令应停止所有早于5分钟的IE进程:
Get-Process |
select -Property ProcessName, StartTime |
? { (($_.StartTime -ne $null) -and
(([DateTime]::Now - $_.StartTime).TotalMinutes -ge 5) -and
($_.ProcessName -eq "iexplore")) } |
Stop-Process
如果只想删除CPU使用率高的第一个进程:
get-process iexplore | sort –descending cpu | select –First 1 | stop-process