when im running this powershell script:
$CPU = (gwmi Win32_PerfFormattedData_PerfProc_Process | ? {$_.Name -eq 'XXXX'}).PercentProcessorTime
if($CPU -ge 90)
{
Get-Process -Name XXXX | Stop-Process -Force
Start-Service -Name XXXX
Function sendEmail ([String] $body)
{
$MailMessage = New-Object System.Net.Mail.MailMessage
$MailMessage.From = “XXXX@XXXX.local”
$MailMessage.To.Add(“XXXX@XXXX.com”)
$MailMessage.Subject = “XXXX!!!”
$MailMessage.Body = $body
$MailMessage.Priority = “High”
$SMTPClient = New-Object System.Net.Mail.SMTPClient
$SMTPClient.Host = “XXXX-exchange.XXXX.XXXX.com”
$SMTPClient.Send($MailMessage)
}
Else
{Exit}
Im getting this error message:
what is wrong with my script?
the purpse of this script is: when there is a high cpu on a specified process kill this process and start a specified service and send an email about that, if the condition is not meet just exit
thanks a lot