How to Get a List of Processes Similar to the Task Manager in PowerShell

John Wachira Feb 15, 2024
How to Get a List of Processes Similar to the Task Manager in PowerShell

This article illustrates how we can get performance metrics from our local computer on PowerShell. We use the Get-Counter cmdlet in PowerShell to fetch the performance counter data from the performance monitoring program on Windows.

Use Get-Counter to Get a List of Processes Similar to the Task Manager in PowerShell

As we mentioned earlier, the Get-Counter cmdlet will let us list all available performance counters and monitor and display data from the counters. The cmdlet works for both local and remote systems.

The Get-Counter cmdlet will default display a set of counters in a one-second interval. Since most counter sets (metrics) are protected by ACL (access control lists), it is advisable to run PowerShell as administrator.

Get-Counter

get-counter

The default counters listed deal with the network, processor, and memory. It also lists some data about the hard drive.

To get a list of all counter sets on a local computer, run the below command.

Get-Counter -ListSet *

counter sets

Adding the ListSet parameter and an asterisk (*) instructs the Get-Counter cmdlet to fetch a list of all counters set in our computer. Note the dot (.) in the MachineName column; this represents our local computer.

We can pick a counter set and specify the sample interval and the maximum number of samples. The example below will fetch metrics from all the processors on our local computer.

The cmdlet will fetch data in a three-second interval and display four samples.

Get-Counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 3 -MaxSamples 4

processor metrics

In the command above, we used the Counter parameter to give the counter path \Processor(_Total)\% Processor Time. We then set a three-second interval with the SampleInterval parameter for the specified counter.

The MaxSamples parameter dictates four as the maximum number of times we check the counter. If you want to fetch continuous samples of a specific counter, use the -Continuous parameter as illustrated below:

Get-Counter -Counter "\Processor(_Total)\% Processor Time" -Continuous

This will continuously fetch samples in a one-second interval until you break the execution. You can do this by pressing CTRL+C.

You can specify the intervals with the SampleInterval parameter.

You can sort the list in alphabetical order, as shown below:

Get-Counter -ListSet * |
  Sort-Object -Property CounterSetName |
    Format-Table CounterSetName, CounterSetType -AutoSize

alphabetic counter sets

The results are set down the pipeline to the Sort-Object cmdlet. The Property parameter dictates that the CounterSet objects should be sorted by CounterSetName.

The results are then passed down the pipeline to Format-Table. The AutoSize parameter minimizes truncation by adjusting the column width.

If you want to get a list of processes similar to the ones displayed in the Windows task manager, you can use the command below:

Get-Counter "\Process(*)\Working Set - Private"

conter set for processes running

To get the handle count, run the command below:

Get-Counter "\Process(*)\Handle Count"

handle count

In a nutshell, the Get-Counter cmdlet is the go-to command when we want to monitor the performance metrics of different counter sets in both local and remote systems.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn