What It Does
The script is read-only. It samples total CPU use and available memory for SampleSeconds, one sample every 5 seconds plus one at the start, and rounds the average CPU and the lowest available-memory percentage to whole numbers. It alerts when that CPU value is over CpuPercent or that memory value is under MemoryPercent.
CPU comes from the Windows performance counters through CIM, the _Total instance of the processor counter, so it is Windows' own processor-time figure, and Task Manager's figure can differ a little. Available memory is the AvailableMBytes counter, which counts standby cached memory as available.
The table lists up to five processes by average CPU use during the sample and up to five by working set after the sample. These are leads for triage. Processes with the same name are listed one by one, and CPU per process is a share of the whole PC across all cores.
A short sample is a spot check, not a trend: a spike that ends before the run starts is not seen. Schedule it often and raise SampleSeconds for machines with bursts.
Before You Run It
- Schedule it often rather than relying on one run. A spike that ends before the run is not seen.
- Raise SampleSeconds for machines with bursts, and tune CpuPercent and MemoryPercent to the PC's role.
- Compare with get-slow-pc-diagnostics when a user reports slowness and this does not alert.
- Run it from your RMM and alert on exit 1.
Type and Risk
- Type: Monitor. It checks one condition. It exits 1 when it finds the problem, so your RMM can alert on it, 0 when all is well, and 2 when it could not run.
- Risk: Low. It reads and changes nothing.
- Restart: It never restarts the machine.
- Typical run: About SampleSeconds plus 5 seconds.
- Example answer: "CPU 96% average over 30 s (limit 90%); memory 8% available (limit 10%); top CPU: chrome 41%, MsMpEng 22%"
- Tested before listing on Windows 11 with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.
Inputs
Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.
- SampleSeconds: How long to sample, in seconds. Whole number, 5 to 300. Default 30. One sample every 5 seconds, plus one at the start.
- CpuPercent: Alert when the average CPU use over the sample is above this percent. Whole number, 0 to 100. Default 90.
- MemoryPercent: Alert when available memory dropped below this percent of installed RAM during the sample. Whole number, 1 to 99. Default 10.
Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.
License
Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.