Just a quick little snippet that can be used if you want something like email alerts from a script to add an email address to maybe a NOC, but only want it to happen after hours or on the weekends.
function SendMail()
{
$Msg = new-object Net.Mail.MailMessage
$SmtpServer = "mail.myserver.com"
$Smtp = new-object Net.Mail.SmtpClient($SmtpServer)
$Msg.From = "from@myserver.com"
$Msg.ReplyTo = "replyto@myserver.com"
$Msg.To.Add("myemail@example.org")
if ($D.Hour -ge '17' -and $D.Hour -le '7' -or $D.DayOfWeek -eq 'Saturday' -or $D.DayOfWeek -eq 'Sunday')
{$Msg.To.Add("noc@example.org") }
$Msg.Priority = [System.Net.Mail.MailPriority]::High
$Msg.subject = "Example Subject"
$Msg.body = "Example Body "
$Smtp.Send($Msg)
}
$d = (Get-Date)
SendMail
(40)