Share via


Need powershell script to alert me on high memory usage on a list of server ?

Question

Saturday, August 22, 2015 10:49 PM

Im a powershell noob. Can someone help me with obtaining a powershell script  run on  a list multiple servers and alerts me by email  when threshold has crossed more than 3 gb.. I will have the script run by scheduled task every 10 minutes. Thanks in advance.

All replies (2)

Sunday, August 23, 2015 12:10 AM ✅Answered | 1 vote

Hi there,

for this there are many possible solutions.

This could be done may be with Events via WMI, also a neverending script or a scheduled task like you mentioned.

I have written a simple script for the last way which should help you with this task:

$computers="localhost"

foreach ($computer in $computers)
{
    $mem = gwmi -Class win32_operatingsystem -computername localhost | Select-Object @{Name = "MemoryUsage"; Expression = { “{0:N2}” -f (($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)/1MB)}}
    if ($mem.MemoryUsage -gt 3 )
    {
        Send-MailMessage -From "[email protected]" -To "[email protected]" -Subject "Memory high" -Body "$computer OOM!"
    }    
}

The intention was to have one "control server" testing the memory of all others. A simple endless loop could be done with:

do
{
#
#Script here
#
    Start-Sleep -Seconds 600
}
while ($true)

But be careful - if a Server gets hig memory-usage you would get an E-Mail every 10 minutes ;)

Greetings,

David das Neves

Technology Specialist - Consulting Services
Computacenter AG & Co. oHG - München

Blog    

Caution: This post may contain errors.


Sunday, August 23, 2015 2:29 AM | 1 vote

Scripting aside, if your firm can spend some money on monitoring systems like SCOM it will save you lots of headache down the road.