Search code examples
powershell

How to get CPU usage & Memory consumed by particular process in powershell script


I want to find performance of single process, as example "SqlServer"

Which commands I should write to find out 2 things:

  1. RAM utilized by SqlServer
  2. CPU utilized by SqlServer

I found lot of solutions listing all processes, but I want to get only 1 i.e. SqlServer.


Solution

  • The command to get SQL server process information:

    Get-Process SQLSERVR
    

    The command to get information for any process that starts with S:

    Get-Process S*
    

    To get the amount of virtual memory that the SQLServer process is using:

    Get-Process SQLSERVR | Select-Object VM
    

    To get the size of the working set of the process, in kilobytes:

    Get-Process SQLSERVR | Select-Object WS 
    

    To get the amount of pageable memory that the process is using, in kilobytes:

    Get-Process SQLSERVR - Select-Object PM
    

    To get the amount of non-pageable memory that the process is using, in kilobytes:

    Get-Process SQLSERVR - Select-Object NPM
    

    To get CPU (The amount of processor time that the process has used on all processors, in seconds):

    Get-process SQLSERVR | Select-Object CPU
    

    To better understand the Get-Process cmdlet, check out the documentation on technet here.