How To Find The Top “N” Processes Using PowerShell That Consumes The Maximum Memory

Share a sample workflow that uses PowerShell script to find the top “N” processes using PowerShell that consumes the maximum memory and also share a sample implementation of using Powershell scripts with UiPath Studio.

Sample Script:

param

(

[Parameter(Mandatory=$true)] [string]$ProcessCount

)

ps | sort -p ws | select -last $ProcessCount | Out-File "Full Path of Output file"

P.S: Use this code in Notepad and save the same with anyName.ps1. Ensure to update "Full Path of Output file" parameter with the File path of the anyName.ps1.

Steps to Implement:

Note: Assuming the User will provide the number of processes ('N') as Input.

  1. Open UiPath Studio and create a sample process.
  2. Search for Input Dialog activity in Activities pane.
image.png
  1. Drag “Input Dialog” activity from the Activities pane into the designer pane to get the Input from the Human User and save the same to a variable.

image.png

  1. Search and Drag “Invoke Power Shell" activity into the designer panel.
  2. Enter the required parameters as shown below along with the input arguments.
  • CommandText: Provide the Full file path of the saved script.
  • Type Argument: System.Management.Automation.PSObject
  • Input parameter: Variable stored as an output for Input dialog activity.
image.png

image.png

  1. Execute the automation script (When prompted, provide the desired value of Input dialog).
  2. Open the output file to see the below outcome:

image.png

Read more on Get Process .