Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Physical memory mail alert when it reaches certain value

$
0
0


Could you please help me in correcting the below.Being completely new to scripting unable to get the output through mail.

$Threshold = 20

$output = gwmi -Class win32_operatingsystem | Select-Object @{N="MemoryUsage"; Expression = {“{0:N2}” -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100/ $_.TotalVisibleMemorySize)) }} | ft -AutoSize |Out-String

write-host "CPU utilization is Currently at $output`%"

If($output -ge $Threshold)
{
Send-MailMessage –From xxx@abc.com –To xxx@efg.com –Subject " MemoryUsage of the Host " -Body "Please find the below Details $output" –SmtpServer (XXXX)
write-host "mail sent"
}

Requirement: Whenever the Physical memory usage meets certain threshold limit it should generate an email.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>