Author Posts

March 7, 2017 at 9:18 am

Wrote a script which will give me CPU, MEM, DISK usage. But, I am not able to get weekly report of this. Can someone help me, what I am missing here:

$ServerListFile = "C:\Users\venkatak\Desktop\Test\ServerList.txt"
$ServerList = Get-Content $ServerListFile -ErrorAction SilentlyContinue
$Result = @()
ForEach($computername in $ServerList)

$AVGProc = Get-WmiObject -computername $computername win32_processor |
Measure-Object -property LoadPercentage -Average | Select Average
$OS = gwmi -Class win32_operatingsystem -computername $computername |
Select-Object @{Name = "MemoryUsage"; Expression = {“{0:N2}” -f ((($_.TotalVisibleMemorySize – $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize) }}
$vol = Get-WmiObject -Class win32_Volume -ComputerName $computername -Filter "DriveLetter = 'C:'" |
Select-object @{Name = "C PercentFree"; Expression = {“{0:N2}” -f (($_.FreeSpace / $_.Capacity)*100) } }

$result += [PSCustomObject] @{
ServerName = "$computername"
CPULoad = "$($AVGProc.Average)%"
MemLoad = "$($OS.MemoryUsage)%"
CDrive = "$($vol.'C PercentFree')%"

$Outputreport = " Server Health Report

Server Health Report

Server Name
Avrg.CPU Utilization
Memory Utilization
C Drive Utilizatoin"

Foreach($Entry in $Result)

if(($Entry.CpuLoad) -or ($Entry.memload) -ge "80")
$Outputreport += ""
$Outputreport += ""
$Outputreport += "$($Entry.Servername)$($Entry.CPULoad)$($Entry.MemLoad)$($Entry.Cdrive)"
$Outputreport += ""

$Outputreport | out-file C:\Users\venkatak\Desktop\Test\Test.htm


March 7, 2017 at 9:46 am

Please, can you elaborate what you mean with "not able to get weekly report of this".


March 7, 2017 at 10:42 am

When I run the script, it is giving me the current usage. But I am looking for a week history (cpu, mem, disk usage).


March 7, 2017 at 10:50 am

The values returned by those CIM classes are point in time values. if you want historical trends you'll have to capture the data a number of times per week to have anything meaningful. In many ways you'd be better off looking at the performance counters and capturing their output

March 7, 2017 at 2:27 pm

Have a look at our eBooks menu. There's a free one on building trend and historical reports that addresses this question exactly and even has some examples along these lines.