# Script to list running processes on Windows devices

An endless number of processes and programs run constantly on a device, both in the foreground and the background. A process is an instance of an executing program or a set of instructions that on execution helps obtain a desired outcome. Using Hexnode’s [Execute Custom Script](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) feature, the system administrator can deploy custom scripts to fetch filtered information about processes based on their **memory usage**, **CPU time**, **process owner**, etc., across all the deployed Windows devices via the Hexnode portal.

 Disclaimer: 
The sample scripts provided below are adapted from third-party open-source sites.

 

Batch script
------------

To view the list of all running processes on a Windows device, use the following script. It will fetch the **Image name** (the name of the process with extension) and other details about each process.

Batch script to fetch running processes

tasklist 

   1

  tasklist 

   

 

  

The `tasklist` command is used to display a list of currently running processes on the local computer or a remote computer.

[![Table of running processes on Windows device](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2023/01/Fetch-running-processes-on-Windows-device.png)](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2023/01/Fetch-running-processes-on-Windows-device.png)You can also include different parameters in the script to apply different filters, and/or obtain the output in your desired format.

- *` fo`* : It specifies the format to use for the output. The valid values are table, list, and CSV. The default format for output is a table.
- *` fi`* : It specifies the types of processes to include in or exclude from the query.

Hence, if you would like to obtain the data in a list format, you can deploy the following script.

Batch script to list running processes

tasklist /fo list

   1

  tasklist /fo list

   

 

  

[![List of running processes on Windows device](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2023/01/Fetch-running-processes-in-list-format.png)](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2023/01/Fetch-running-processes-in-list-format.png)If you would like to list processes that are occupying more than a certain amount of **memory**, you can deploy the following script.

Batch script to filter running processes based on memory usage

tasklist /fo list /fi "MEMUSAGE gt 'Memory usage in KB'" 

   1

  tasklist /fo list /fi "MEMUSAGE gt 'Memory usage in KB'" 

   

 

  

[![Processes on Windows devices more than 1000 KB](https:2023/01/Filter-running-processes-based-on-memory-usage.png)](https:2023/01/Filter-running-processes-based-on-memory-usage.png)You can also filter the processes based on **CPU time/process time**, i.e., the time taken by the CPU to process a program.

Batch script to filter running process on CPU Time

tasklist /fo list /fi "CPUtime gt 'time in the format HH:MM:SS'" 

   1

  tasklist /fo list /fi "CPUtime gt 'time in the format HH:MM:SS'" 

   

 

  

For example, `tasklist /fo list /fi “CPUtime gt 00:01:00”` will list all running processes that have CPU time greater than 1 minute in list format.

[![Processes on Windows devices with more than 1 minute of CPU time](https:2023/01/Filter-running-processes-based-on-CPU-time.png)](https:2023/01/Filter-running-processes-based-on-CPU-time.png)PowerShell script
-----------------

To list all the running processes on a Windows device, you can use the following script. It will fetch the **ProcessName** and other details related to each process.

Script to fetch running processes

Get-Process

   1

  Get-Process

   

 

  

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

[![List of running processes on a Windows device](https:2023/01/Fetch-running-processes-on-a-Windows-device.png)](https:2023/01/Fetch-running-processes-on-a-Windows-device.png)However, the output obtained by the above script may contain a bunch of other details about the processes as well. You can use the following command to just list the names of the processes.

Script to fetch process names

Get-Process | Select ProcessName

   1

  Get-Process | Select ProcessName

   

 

  

[![List of running processes on a Windows device](https:2023/01/List-of-running-processes-on-a-Windows-device-.png)](https:2023/01/List-of-running-processes-on-a-Windows-device-.png)You can also fetch properties of a particular process by specifying the **process name**. For the process name of the concerned process, refer to the list of running processes obtained from the previous script.

Script to fetch process info

Get-Process 'ProcessName' | Format-List \*

   1

  Get-Process 'ProcessName' | Format-List \*

   

 

  

For example, `Get-Process msedge | Format-List *`

`Format-List *` displays all the available properties in a list format.

[![Info about a running process on a Windows device](https:2023/01/Fetch-info-about-the-process-on-a-Windows-device.png)](https:2023/01/Fetch-info-about-the-process-on-a-Windows-device.png)A device may be host to multiple user accounts, and some processes may be unique to a user. Using the following script, you can determine the **owner of a process**.

Script to fetch process owner

Get-Process 'ProcessName’ -IncludeUserName | Select UserName, ProcessName 

   1

  Get-Process 'ProcessName’ -IncludeUserName | Select UserName, ProcessName 

   

 

  

For example, `Get-Process msedge -IncludeUserName | Select UserName, ProcessName`

[![Process owner of a running process on a Windows device](https:2023/01/Fetch-the-owner-of-a-process-on-a-Windows-device-e1674034824193.png)](https:2023/01/Fetch-the-owner-of-a-process-on-a-Windows-device-e1674034824193.png) Notes:- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode UEM will not be responsible for any damage/loss to the system on the behaviour of the script.