$machines = gc "D:\tool.txt" $Threshold = 80 ForEach($computername in $machines){ $Output = Get-WmiObject -Class Win32_Operatingsystem | Select-Object @{N="MemoryUsage"; Expression = {“{0:N2}” -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100/ $_.TotalVisibleMemorySize)) }} Write-Host "CPU utilization is Currently at"$($Output.MemoryUsage)"`% " $Outputreport = "<HTML><TITLE> Server Memory Utilization Report </TITLE><BODY background-color:cyan ><font color ="" CC3333 "" face=""Microsoft Tai le""><H2> Server Memory Report </H2></font><Table border=2 cellpadding=2 cellspacing=1><TR bgcolor= cyan align=center><TD><B> Server Name</B></TD><TD><B>Memory Utilization</B></TD>" If($Output.MemoryUsage -ge $Threshold) { $Outputreport += "<TR bgcolor=#80e5ff>" } $Outputreport += "<TD>$($machines)</TD><TD align=center>$($Output.MemoryUsage)</TD></TR>" } $Outputreport += "</Table></BODY></HTML>" $Outputreport | out-file F:\Test.htm write-host "Mail Sent" $SmtpServer = 'XXXX' $To = 'XXXX' $From = 'xxxx' $messagesubject = 'Memory Alert' $message = New-Object System.Net.Mail.MailMessage $from, $to $message.Subject = $messageSubject $message.IsBodyHTML = $true $message.body = Get-Content F:\Test.htm $smtp = New-Object Net.Mail.SmtpClient($smtpServer) $smtp.Send($message) #If
Able to get the output of current memory usage but its not giving the right output.
↧
HTML Output in mail for Physical memory Usage when it reaches certain limit
↧