Powershell widget to display top 5 resource consuming processes

Long, Steven 36 Reputation points
2023-07-06T13:47:33.6766667+00:00

We need to create a dashboard for 3 specific devices.

It needs to be 2 panes for each device, one for the top 5 memory consuming processes, and 1 for the top 5 cpu consuming processes.

Can anyone help?

I am basically incompetent in PS.

Operations Manager
Operations Manager
A family of System Center products that provide infrastructure monitoring, help ensure the predictable performance and availability of vital applications, and offer comprehensive monitoring for datacenters and cloud, both private and public.
1,521 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,747 questions
0 comments No comments
{count} votes

Accepted answer
  1. XinGuo-MSFT 20,401 Reputation points
    2023-07-07T02:32:58.7866667+00:00

    Here's an example of a PowerShell script that accomplishes this task:

    # Specify the device names
    $devices = "Device1", "Device2", "Device3"
    
    foreach ($device in $devices) {
        Write-Host "Device: $device"
    
        # Get the top 5 memory-consuming processes
        $memoryProcesses = Get-Process -ComputerName $device | Sort-Object -Property WS -Descending | Select-Object -First 5
    
        Write-Host "`nTop 5 Memory Consuming Processes:"
        $memoryProcesses | Format-Table Name, WS -AutoSize
    
        # Get the top 5 CPU-consuming processes
        $cpuProcesses = Get-Process -ComputerName $device | Sort-Object -Property CPU -Descending | Select-Object -First 5
    
        Write-Host "`nTop 5 CPU Consuming Processes:"
        $cpuProcesses | Format-Table Name, CPU -AutoSize
    
        Write-Host "--------------------------------------------------`n"
    }
    
    

    Here's how you can use this script:

    Open a text editor and copy the script into a new file with a .ps1 extension (e.g., dashboard.ps1). Modify the $devices variable to contain the names or IP addresses of your three devices (e.g., "Device1", "Device2", "Device3"). Save the file. Open PowerShell and navigate to the directory where you saved the script. Run the script by entering its name (e.g., .\dashboard.ps1) and press Enter. The script will iterate over each device, retrieve the top 5 memory-consuming and CPU-consuming processes, and display the results in separate panes for each device.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.