The Get-Process
cmdlet in PowerShell is used to retrieve information about the processes that are running on a local or remote computer. This cmdlet provides details such as the process name, process ID, memory usage, CPU time, and more. You can use it to monitor system performance, troubleshoot issues, or collect data for system administration tasks.
Basic Syntax:
Get-Process
Example 1: List All Running Processes
Running Get-Process
without any parameters will list all the processes currently running on your local machine.
Get-Process
This will output a list of processes, showing the Name, ID, Handles, NPM (Non-paged memory), PM (Paged memory), WS (Working set), and CPU time, among other details.
Example 2: Get Specific Process by Name
You can filter processes by their name. For example, to get all processes related to "chrome" (Google Chrome):
Get-Process -Name chrome
This will list all running chrome processes.
Example 3: Get Process by Process ID (PID)
You can retrieve a process using its PID (Process ID). For instance, to get the process with PID 1234:
Get-Process -Id 1234
This will return information about the process with the specified PID.
Example 4: Get Multiple Processes by Name
You can also specify multiple processes by separating their names with commas. For example:
Get-Process -Name chrome, firefox, explorer
This will return information about processes related to chrome, firefox, and explorer.
Example 5: Display Specific Properties of Processes
You can select specific properties of the processes to make the output more readable. For example, to display the Name, ID, CPU time, and Memory of each process:
Get-Process | Select-Object Name, Id, CPU, WorkingSet
This will show a simplified output with just the Name, ID, CPU, and WorkingSet (memory usage) of each process.
Example 6: Sort Processes by Memory Usage
To sort the processes by memory usage (working set), use the following command:
Get-Process | Sort-Object WorkingSet -Descending
This will list the processes, sorted by memory usage in descending order.
Example 7: Get Process on a Remote Machine
If you want to get processes from a remote machine, use the -ComputerName
parameter. For example:
Get-Process -ComputerName "RemotePCName"
This command retrieves the processes from the remote computer specified by RemotePCName.
Example 8: Limit the Output to Top N Processes
To limit the number of processes returned, you can use Select-Object
to return only the top N processes. For example, to get the top 5 processes by CPU usage:
Get-Process | Sort-Object CPU -Descending | Select-Object -First 5
This will show the top 5 processes sorted by their CPU usage in descending order.
Example 9: Get Process for Specific User
To retrieve processes run by a specific user, you can use the Get-WmiObject
cmdlet along with Get-Process
. Here's an example:
Get-WmiObject -Class Win32_Process | Where-Object { $_.Owner -eq "username" }
Replace "username" with the actual username. This command fetches processes based on the specified user.
Example 10: Display Processes with Memory and CPU Usage
To display detailed information on processes, including their memory and CPU usage, you can run:
Get-Process | Select-Object Name, Id, CPU, WorkingSet, PrivateMemorySize
This shows the Name, Id, CPU time, WorkingSet (memory), and PrivateMemorySize (private memory allocated to the process).
Example 11: Killing a Process
If you want to stop a process, you can use the Stop-Process
cmdlet. For example, to kill a process by name (e.g., notepad):
Stop-Process -Name notepad
Or, if you know the PID:
Stop-Process -Id 1234
Example 12: Getting Process in a Specific Session
You can filter processes by their session ID. For example:
Get-Process | Format-Table -Property Name, Id, CPU, WorkingSet
This will return processes running under session ID 1.
Example 13: Displaying Processes in a Specific Format (Table, List, or Grid)
You can display the output in different formats, such as table, list, or grid. For example:
-
Table format (default):
Get-Process | Format-Table -Property Name, Id, CPU, WorkingSet
-
List format (for detailed info):
Get-Process | Format-List -Property Name, Id, CPU, WorkingSet
-
Grid format (for a more interactive view):
Get-Process | Out-GridView
Â
The Get-Process
cmdlet in PowerShell is a powerful tool for managing and monitoring processes on a local or remote computer. You can filter, sort, display, and even manipulate processes using various parameters and techniques, making it an essential cmdlet for system administrators and users performing troubleshooting or monitoring tasks.