Requirement: Whenever the Physical memory usage meets certain threshold limit it should generate an email.
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.