CPU, MEM, DISK weekly usage

Welcome Forums General PowerShell Q&A CPU, MEM, DISK weekly usage

This topic contains 4 replies, has 4 voices, and was last updated by

 
Keymaster
1 year, 8 months ago.

  • Author
    Posts
  • #65926

    Participant
    Points: 0
    Rank: Member

    Hi,
    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 += ""
    }
    else
    {
    $Outputreport += ""
    }
    $Outputreport += "$($Entry.Servername)$($Entry.CPULoad)$($Entry.MemLoad)$($Entry.Cdrive)"
    }
    $Outputreport += ""
    }

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

    -Kalyan

  • #65929

    Moderator
    Points: 24
    Team Member
    Rank: Member

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

    Thanks,
    Daniel

  • #65934

    Participant
    Points: 0
    Rank: Member

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

    -Kalyan

  • #65937

    Participant
    Points: 0
    Rank: Member

    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

  • #65938

    Keymaster
    Points: 1,638
    Helping HandTeam Member
    Rank: Community Hero

    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.

The topic ‘CPU, MEM, DISK weekly usage’ is closed to new replies.