Powershell Script to email you your lunch break

#Sets $theTime variable to the current time.
$lunchStarted = Get-Date
$lunchStartsUKDate = $lunchStarted.ToLongDateString()
$lunchStartsUKTime = $lunchStarted.ToShortTimeString()

$HOST.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”) | OUT-NULL
$HOST.UI.RawUI.Flushinputbuffer()

$lunchEnded = Get-Date
$lunchEndsUKDate = $lunchEnded.ToLongDateString()
$lunchEndsUKTime = $lunchEnded.ToShortTimeString()

#Define hub transport server
$smtpServer = “smtp server”

#Define email sender and recipient
$sender = “sender”
$recipient = “recipient”

#Define email subject and body
$msgSubject = “Lunch!”
$msgBody_Text = “You went out to lunch at $lunchStartsUKDate $lunchStartsUKTime, and came back at $lunchEndsUKDate $lunchEndsUKTime”

#Send it
Send-MailMessage -to $recipient -from $sender -subject $msgSubject -body $msgBody_text -smtpserver $smtpServer

Advertisements