I want to make a script that checks two time if a process is running. First I would like to check normally if a process is running and second time I want to wait 30 seconds until the next check.
Here I have something like this:
$check=Get-Process hl -ErrorAction SilentlyContinue
if ($check -eq $null) {
Start-Sleep -s 30
}
If in both cases the process is not running I want poweshell to send me a mail with this :
$EmailFrom = “[email protected]”
$EmailTo = “[email protected]”
$Subject = “Process not running”
$Body = “NOT RUNNING”
$SMTPServer = “smtp.gmail.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“user”, “pass”);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
It's something with and but I can't figure out how exactly.
So it will be something like this: if process not running {sleep} and if second time checking not running {mail}