-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
705a520
commit 9ab760a
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
content/posts/2023-05-01-use-powershell-to-monitor-system-performance.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
categories: | ||
- PowerShell | ||
date: 2023-05-01T11:15:00+01:00 | ||
draft: false | ||
lastMod: 2023-05-01T11:15:00+01:00 | ||
tags: | ||
- PowerShell | ||
title: Use PowerShell to monitor system performance | ||
--- | ||
|
||
In this post, I'll show you how to monitor system performance using PowerShell. | ||
I'll introduce you to a few different cmdlets and some examples of how you | ||
might use them to monitor the performance of a system. | ||
|
||
## `Get-Process` | ||
|
||
This cmdlet provides information about all of the running processes on a | ||
system, including their process ID, their CPU usages, and their memory usage. | ||
|
||
You might use this cmdlet to: | ||
|
||
- Get the five processes using the most CPU: | ||
`Get-Process | Sort-Object -Property CPU | Select-Object Name,CPU -Last 5`. | ||
- Get the five processes using the most memory: | ||
`Get-Process | Sort-Object -Property WorkingSet | Select-Object Name,WorkingSet -Last 5` | ||
- Get the total CPU time of a specific process: | ||
`(Get-Process -Name msedge).TotalProcessorTime` | ||
|
||
## `Get-Counter` | ||
|
||
This cmdlet provides information about system performance counters, such as | ||
CPU, memory, and disk usage. | ||
|
||
You might use this cmdlet to: | ||
|
||
- Check free space on a drive: | ||
`(Get-Counter '\LogicalDisk(C:)\% Free Megabytes').CounterSamples.CookedValue/1024` | ||
- Check the amount of available memory: `Get-Counter '\Memory\Available MBytes'` | ||
- Check network traffic: `Get-Counter '\Network Interface(*)\Bytes Total/sec'` | ||
|
||
## `Get-WmiObject` | ||
|
||
This cmdlet provides access to the Windows Management Instrumentation (WMI) | ||
database, which contains information about system resources. | ||
|
||
You might use this cmdlet to: | ||
|
||
- Check system uptime: | ||
`Get-WmiObject -Class Win32_OperatingSystem | Select-Object -Property LastBootUpTime | ForEach-Object {[System.Management.ManagementDateTimeConverter]::ToDateTime($_.LastBootUpTime)} | Select-Object -ExpandProperty DateTime` | ||
- Check system battery status: | ||
`Get-WmiObject -Class Win32_Battery | Select-Object -Property BatteryStatus,EstimatedChargeRemaining` | ||
- Check system fan speeds: | ||
`Get-WmiObject -Namespace "root\cimv2" -Class "Win32_Fan" | Select-Object -Property DeviceID, CurrentSpeed` | ||
|
||
## Further reading | ||
|
||
Further information on the `Get-Process` cmdlet can be found on | ||
[Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-process). | ||
|
||
Further information on the `Get-Counter` cmdlet can be found on | ||
[Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.diagnostics/get-counter). | ||
|
||
Further information on the `Get-WmiObject` cmdlet can be found on | ||
[Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-wmiobject). |