Powershell

How to Monitor System Performance with PowerShell

The performance of the system in Windows is monitored by using the “Performance Monitor” application. However, PowerShell users can also monitor system performance by using certain commands. One such command is “Get-Counter” cmdlet. This command is capable of countering the system performance on remote and remote computers. It can monitor CPU usage, disk usage, or memory usage using PowerShell.

This article will look at the methods to monitor the system performance using PowerShell.

How to Monitor System Performance with PowerShell?

The performance of the system performance can be checked using the number of methods, some of which are listed below:

Example 1: Display System Information

To display the system information using PowerShell, first, use the “Get-WmiObject” cmdlet and then assign a “Win32_ComputerSystem” class to the “-Class” parameter. Next, pipe it to the “Select-Object” cmdlet and then specify the types separated by comma whose information you want to display:

Get-WmiObject -Class Win32_ComputerSystem | Select-Object Name, SystemType, Manufacturer, Model, TotalPhysicalMemory

Example 2: Check CPU Usage

To get the details of the CPU usage, first, specify the “Get-Counter” cmdlet and specify the query “\Processor(_Total)\% Processor Time” and concatenate it with the “CounterSamples” cmdlet. After that, pipe the whole query to the “ForEach-Object” cmdlet. Next, specify the “$_.InstanceName” variable to retrieve the CPU variables display name and then create the “$_.CookedValue” variable to get the usage in numbers:

(Get-Counter "\Processor(_Total)\% Processor Time").CounterSamples | ForEach-Object {$_.InstanceName + ": " + $_.CookedValue + "%"}

Example 3: Monitor Memory Usage

Execute the below query in PowerShell to retrieve the total memory usage:

(Get-Counter "\Memory\Available MBytes").CounterSamples | ForEach-Object {"Free Memory: " + $_.CookedValue + " MB"}

Example 4: Check Disk Usage

To retrieve the total CPU usage in PowerShell, execute the given query:

(Get-Counter "\LogicalDisk(*)\% Free Space").CounterSamples | ForEach-Object { $_.InstanceName + ": " + $_.CookedValue + "%" }

Example 5: Get the Performance of a Specified Counter

In order to retrieve the detailed performance of a specific counter, first, specify the “Get-Counter” cmdlet, add the “-ListSet” parameter along with the wild character, and pipe it to the “Where-Object” cmdlet. After that create a matching filter and assign it to the “-FilterScript” parameter:

Get-Counter -ListSet * | Where-Object -FilterScript {$PSItem.countersetname -match "Windows"}

Example 6: Get the Performance of a Single Counter

Lastly, to retrieve the performance of a single counter, first, use the “Get-Counter” cmdlet along with the “-ListSet” parameter and specify the counter name which is “Memory”:

Get-Counter -ListSet "Memory"

It can be observed that the performance details of the specified counter are displayed in the above output.

Conclusion

To monitor the system performance with PowerShell, use the “Get-Counter” cmdlet. This cmdlet can monitor the CPU usage, memory usage, and disk space usage with PowerShell. This write-up has explained the process to check the system performance with PowerShell.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.