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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s