PS-Commands/Scripts/Send-Message-PIV.ps1
2023-10-03 22:02:33 +03:00

22 lines
No EOL
906 B
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

$Username = "support@domain.local";
$Password = "password";
$SendTo = "admin@domain.ru";
$MailServer = "mail.domain.ru";
$HostName = $args[0];
$IPAddress = $args[1];
$PingStatus = $args[2];
$FailedOn = $args[3];
$message = new-object Net.Mail.MailMessage;
$message.From = $Username;
$message.To.Add($SendTo);
$message.Subject = "Ping Info View";
$message.Body = "Failed ping: `r`nHost Name: $HostName`r`nIP Address: $IPAddress`r`nPing Status: $PingStatus`r`nPing Time: $FailedOn";
$smtp = new-object Net.Mail.SmtpClient($MailServer, "25");
$smtp.EnableSSL = $true;
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.send($message);
# F9 - Advanced Options - Execute the following command on failed ping:
# Powershell.exe -executionpolicy remotesigned -File С:\Send-Message-PIV.ps1 "%HostName%" "%IPAddress%" "%LastPingStatus%" "%LastFailedOn%"