Created
February 4, 2020 17:25
-
-
Save emnavarro02/996f40a3982417c656e4142b0e1eb280 to your computer and use it in GitHub Desktop.
Get top process CPU consumers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
####################################################################################################################### | |
# Get Top process CPU Consumers | |
# Author: Emerson Navarro | |
# Version: 0.1 | |
####################################################################################################################### | |
# CHANGE LOG: | |
# - 04/02/2019: | |
# - Initial PID Collumn | |
####################################################################################################################### | |
Param( | |
# The amount of processes returned by the function. Default is 10. | |
[Parameter(Mandatory=$false)] | |
[int] $TOP=10 | |
) | |
$PERF_PROCESS_QUERY = "SELECT * FROM Win32_PerfFormattedData_PerfProc_Process WHERE NOT (Name like 'idle' OR Name like '_Total')" | |
Get-WmiObject -Query $PERF_PROCESS_QUERY | Sort-Object PercentProcessorTime -Descending | | |
Select-Object Name, @{N="ID";E={$_.IDProcess}}, @{N="CPU (%)";E={$_.PercentProcessorTime}}, @{N="Command";E={$(Get-WmiObject -Query "SELECT CommandLine from Win32_Process WHERE ProcessId= $($_.IDProcess)").CommandLine}} -First $TOP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script has an optional parameter to control the amount of processes returned. If no value is provided, script returns top 10 processes
To use this script:
powershell.exe -ExecutionPolicy <_Your_Execution_Policy_> -file .\Get-CPUConsumptionPerProcess.ps1 -Top _<10>_