get-process-powershell-command

Get-Process | Taking on PowerShell one cmdlet at a time | Weekly Blog

Share this post:

This is a part of an on-going blog series written by Adam Gordon. Each week, Adam will walk you through a PowerShell command, showing you when and how to use each one. This week, Adam covers Get-Process.

When to use Get-Process

The Get-Process cmdlet gets the processes on a local or remote computer.

Without parameters, this cmdlet gets all of the processes on the local computer. You can also specify a particular process by process name or process ID (PID) or pass a process object through the pipeline to this cmdlet.

By default, this cmdlet returns a process object that has detailed information about the process and supports methods that let you start and stop the process.

You can also use the parameters of the Get-Process cmdlet to get file version information for the program that runs in the process and to get the modules that the process loaded.

 

How to use Get-Process

Get a list of all active processes on the local computer: 

Get-Process

This command gets a list of all active processes running on the local computer.

Get-Process

 

Get all available data about one or more processes:

 Get-Process winword, explorer | Format-List *

The Get-Process cmdlet gets all available data about the Winword and Explorer processes on the computer.

It uses the –Name parameter to specify the processes, but it omits the optional parameter name.

The pipeline operator | passes the data to the Format-List cmdlet, which displays all available properties * of the Winword and Explorer process objects.

NOTE: You can also identify the processes by their process IDs. For instance, Get-Process -Id 600, 403.

Get-Process

 

Get all processes with a working set greater than a specified size:

Get-Process | Where-Object {$_.WorkingSet -gt 20000000}

The Get-Process cmdlet gets all processes that have a working set greater than 20 MB.

The pipeline operator | passes the process objects to the Where-Object cmdlet, which selects only the object with a value greater than 20,000,000 bytes for the –WorkingSet property.

WorkingSet is one of many properties of process objects.

NOTE: To see all of the properties, type Get-Process | Get-Member.

By default, the values of all amount properties are in bytes, even though the default display lists them in kilobytes and megabytes.

Get-Process

 

List processes on the computer in groups based on priority: 

$A = Get-Process
$A | Get-Process | Format-Table -View priority

The first command gets all the processes on the computer and then stores them in the $A variable.

The second command pipes the Process object stored in the $A variable to the Get-Process cmdlet, then to the Format-Table cmdlet, which formats the processes by using the Priority view.

Get-Process

 

The Priority view, and other views, are defined in the PS1XML format files in the PowerShell home directory ($pshome).

Get-Process

Get-Process

 

Get version information for a process:

Get-Process powershell_ise -FileVersionInfo

This command uses the –FileVersionInfo parameter to get the version information for the powershell_ise.exe file that is the main module for the PowerShell ISE process.

NOTE: To run this command with processes that you do not own, you must open PowerShell with the Run as administrator option.

Get-Process

 

Get modules loaded with the specified process:

Get-Process powershell* -Module

This command uses the –Module parameter to get the modules that have been loaded by the process.

NOTE: To run this command with processes that you do not own, you must open PowerShell with the Run as administrator option.

Get-Process

 

Find the owner of a process:

Get-Process powershell_ise -IncludeUserName

The –IncludeUserName parameter requires elevated user rights (Run as Administrator).

Get-Process

 

$p = Get-WmiObject Win32_Process -Filter “name=’powershell_ise.exe'”

$p.GetOwner()

Using Get-WmiObject to get the PowerShell_ISE process. It saves it in the $p variable.

Using the GetOwner method to get the owner of the process in $p.

Get-Process

 

Get all processes that have a main window title and display them in a table:

Get-Process | Where-Object {$_.mainWindowTitle} | Format-Table Id, Name, mainWindowtitle -AutoSize

The –mainWindowTitle property is just one of many useful properties of the Process object that Get-Process returns.

To view all of the properties, pipe the results of a Get-Process command to the Get-Member cmdlet Get-Process | Get-Member.

Get-Process

Need PowerShell training? Check out ITProTV’s PowerShell online IT training courses.

Leave a Reply

Your email address will not be published. Required fields are marked *