How to Use PowerShell Get-Process?

In this tutorial, I will explain how to use the PowerShell Get-Process cmdlet to manage and monitor processes on your computer. As a developer, I once faced an issue where a rogue process consumed excessive CPU resources, causing significant slowdowns. This tutorial will help you understand how to identify and manage such processes effectively using PowerShell’s Get-Process cmdlet.

To use PowerShell Get-Process, simply open PowerShell and type Get-Process to list all running processes. For specific processes, use Get-Process -Name “ProcessName”, replacing “ProcessName” with the desired process name. You can also filter, sort, and select specific properties using additional cmdlets like Sort-Object and Select-Object to manage processes more effectively.

PowerShell Get-Process Cmdlet

The Get-Process cmdlet in PowerShell retrieves information about the processes running on your local computer. It lists all the processes by default, but you can filter and format the output to suit your needs.

Basic Usage

To get a list of all running processes, simply open PowerShell and type:

Get-Process

This command will display a table with details like the process name, ID, CPU usage, and memory usage.

Here is the output you can see in the screenshot below:

PowerShell Get-Process

Check out PowerShell Compare-Object

Filter Processes by Name

If you want to find a specific process, such as notepad, you can filter the results by name using the Get-Process cmdlet.

Get-Process -Name notepad

This command will return all instances of the Notepad process running on your computer.

Here is the exact output you can see in the screenshot below:

How to Use PowerShell get-process

Using Wildcards

You can also use wildcards to search for processes. For example, to find all processes that start with “chrome,” you can use:

Get-Process -Name chrome*

This is particularly useful when you’re not sure of the exact process name.

Check out PowerShell Select-Object

Sort Processes

To sort processes by a specific property, such as CPU usage, you can use the Sort-Object cmdlet:

Get-Process | Sort-Object CPU -Descending

This command will list all processes sorted by CPU usage in descending order, helping you quickly identify the most resource-intensive processes.

I executed the above script, and you can see the exact output in the screenshot below:

PowerShell Get-Process Examples

Display Specific Properties

Sometimes, you might only be interested in certain properties of a process. You can use the Select-Object cmdlet to specify which properties to display:

Get-Process | Select-Object Name, CPU, Id

This command will display only the process name, CPU usage, and process ID.

Check out PowerShell Copy-Item

Stop a Process

If you identify a process that is causing issues, you can stop it using the Stop-Process cmdlet. For example, to stop a process by name:

Stop-Process -Name notepad

Or by process ID:

Stop-Process -Id 1234

Get Processes on a Remote Computer

You can also retrieve processes from a remote computer using the -ComputerName parameter. For example, to get processes from a computer named Server01:

Get-Process -ComputerName Server01

Ensure you have the necessary permissions and that remote management is enabled on the target computer.

Check out PowerShell Write-Output

Real-World Example: Managing Processes in a Corporate Environment

Consider a scenario where you are an IT administrator for a company in San Francisco. You notice that several users are experiencing slow performance due to a resource-heavy application.

You can quickly identify and manage these processes using PowerShell across multiple computers.

Here is the complete PowerShell script.

$computers = @("Workstation01", "Workstation02", "Workstation03")
foreach ($computer in $computers) {
    Get-Process -ComputerName $computer | Sort-Object CPU -Descending | Select-Object -First 5
}

This script retrieves the top 5 CPU-consuming processes from each specified workstation, allowing you to take appropriate action.

Conclusion

The Get-Process cmdlet in PowerShell is used to manage and monitor processes on your computer. You can use the Get-Process cmdlet to troubleshoot performance issues or manage processes across a network. I hope you now understand how to use the PowerShell Get-Process cmdlet with a few useful examples.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.