Sometimes an easy-looking task such as tracking which application/process is causing CPU or RAM performance issues becomes a headache to complete. In this short article, we will provide PowerShell commands that we are using for tracking performance issues related to CPU and Ram quickly and efficiently.
What is choking my CPU?
With the following PowerShell command, we will get the 20 top processes in a percentage descending sorting order:
1 | Get-Counter -ErrorAction SilentlyContinue '\Process(*)\% Processor Time' | Select-Object -ExpandProperty countersamples| Select-Object -Property instancename, cookedvalue| ? {$_.instanceName -notmatch "^(idle|_total|system)$"} | Sort-Object -Property cookedvalue -Descending| Select-Object -First 20| ft InstanceName,@{L='CPU';E={($_.Cookedvalue/100/$env:NUMBER_OF_PROCESSORS).toString('P')}} -AutoSize |
What consumes my Memory?
These commands will give you the total consumed Memory of a System:
1 | $CompObject = Get-WmiObject -Class WIN32_OperatingSystem |
1 | $Memory = ((($CompObject.TotalVisibleMemorySize - $CompObject.FreePhysicalMemory)*100)/ $CompObject.TotalVisibleMemorySize) |
1 | Write-Host "Memory usage in Percentage:" $Memory |
With the following PowerShell command, we will get the 20 top processes that consume memory in a percentage descending sorting order:
1 | Get-WmiObject WIN32_PROCESS | Sort-Object -Property ws -Descending | Select-Object -first 20 processname, @{Name="Mem Usage(MB)";Expression={[math]::round($_.ws / 1mb)}} |
Why not do all the above in task manager?
All the above commands can be scripted and run towards remote computers, servers, and even Windows lists. That means that you can instantly get these statistics from several machines without interfering with someone’s work in progress, minimizing the response time and boosting productivity. Task manager is sometimes difficult to read-pinpoint the root cause of an issue as the graphical image you are getting changes each second. With PowerShell, you are getting an apparent output.
Future articles will also analyze Disk performance problems tracking that will need more extensive PowerShell script methods that measure IOPS (input/output operations per second), indicating disk-related issues. So stay tuned for our next article.
If the above sounds confusing, very technical, or just time consuming for you current capacity, we are here to help Contact us by Clicking Here. We are helping businesses to stabilizing and optimizing their environments. We also offer monitoring as a service if you just want us to keep an eye and alert you if something has indications of the will stop working soon. Here is an article related to monitoring